歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> linux下批量新建賬號及設置密碼

linux下批量新建賬號及設置密碼

日期:2017/3/3 13:49:59   编辑:Linux技術

使用了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

Copyright © Linux教程網 All Rights Reserved