天天看點

批量添加使用者并設定密碼

1.建立users.list檔案并寫入所要建立的使用者:

jake tang monika dove david user2

:wq

2.建立useradd.sh檔案:

#!/bin/bash

#

#batch add users with file called users.list

for username in $(more users.list)

do

if [ -n $username ]

then

 useradd -m $username

 echo

 echo $username"123" | passwd --stdin $username

 echo "User $username's passwd is changed!"

else

 echo "The username is null!"

fi

done

3.添加執行權限: chmod +x useradd.sh

4.兩個檔案放在同一個目錄下,執行即可。

本文轉自 zhuxtqw 51CTO部落格,原文連結:http://blog.51cto.com/1054054/1256313,如需轉載請自行聯系原作者