使用了passwd --std username 代碼如下:
1 #!/bin/bash 2 export PATH=/bin:/sbin:/usr/bin:/usr/sbin 3 if [ test ! -f "account.txt" ];then 4 echo "no account1.txt \n please new one 每行一個帳號名稱" 5 exit 1 6 fi 7 usernames=$(cat account1.txt) 8 for username in $usernames 9 do 10 useradd $username 11 echo $username | passwd --stdin $username 12 chage -d 0 $username #把最後一次修改密碼的日期設置為0,即立即更改密碼 13 done