linux中如何使用脚本批量创建多个用户?

 时间:2026-02-14 18:57:16

1、首先需要创建一个文本文件,使用命令:vim user

linux中如何使用脚本批量创建多个用户?

2、输入需要创建的用户

linux中如何使用脚本批量创建多个用户?

3、完成后按下esc退出编辑,输入“:wq"保存并退出编辑

linux中如何使用脚本批量创建多个用户?

4、然后我们输入命令:vim cu.sh,编辑内容如下:

#!/bin/bash 

read -p "Enter The Users Password : " PASSWD 

for UNAME in `cat user` 

doid $UNAME &> /dev/null

if [ $? -eq 0 ] 

then 

echo "Already exists" 

elseuseradd $UNAME &> /dev/null 

echo "$PASSWD" | passwd --stdin $UNAME &> /dev/null 

if [ $? -eq 0 ] 

then 

echo "$UNAME , Create success" 

else 

echo "$UNAME , Create failure" 

fi 

fi 

done

linux中如何使用脚本批量创建多个用户?

5、编辑完成后按下esc,输入“:wq”保存并退出

linux中如何使用脚本批量创建多个用户?

6、执行命令:sh cu.sh,输入密码

linux中如何使用脚本批量创建多个用户?

7、执行后,我们可以看到ftpq的用户已经自动创建了

linux中如何使用脚本批量创建多个用户?

8、在/home的根目录已经自动创建了ftpq的目录

linux中如何使用脚本批量创建多个用户?

  • microsoft edge怎么扩展程序?
  • list index out of range错误解决方法
  • pycharm怎么安装第三方库
  • python怎么注释多行代码
  • 怎样在Pythoy矩阵让对应位置的数据相加?
  • 热门搜索
    世界旅游胜地有哪些 贵州旅游线路推荐 黑河旅游景点大全 南通旅游网 湖北省旅游条例 美国旅游报价 海边旅游去哪里好 浙江仙居旅游 法国巴黎旅游 去韩国旅游要多少钱