如何在脚本里面批量添加用户和密码

如何在脚本里面批量添加用户和密码,第1张

#!/bin/shi=0whiletruedoleti=i+1echo"u"$i":123456">>/root/user.txtecho"createinguseru$i.."useraddu$iif[$i-eq100]then/usr/sbin/chpasswd/root/user.txt/bin/rm-f/root/user.txtexitfidone#ifyouwanttodeletealloftheuser,youcan#i=0#whiletrue#do#leti=i+1#echo"deleteinguseru$i.."#userdel-ru$i#if[$i-eq100]#then#exit#fi#done供参考

while read line

do

user=`echo $line|cut -d : -f 1`

useradd $user

password = `echo $line | cut -d : -f 2`

echo "$password" | passwd --stdin "$user"

done<userlist.txt

Linux下 Passwd有参数 --stdin This option is used to indicate that passwd should read the new password from standard input, which can be a pipe.

--stdin参数表明passwd可以从标准输入或者管道接收密码


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11844080.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-19
下一篇2023-05-19

发表评论

登录后才能评论

评论列表(0条)

    保存