Create Users And Change Passwords With A Bash Script 通过脚本批量创建用户并设置密码

First create a file which contains all the user name. 首先创建一个包还所有用户名的文件,格式如下:

------------------------
nurealam
nayeem
mrahman
farid
rubi
sankar
------------------------

Save the file as userlist.txt. Now create the following bash file: 把该文件保存为userlist.txt。现在创建如下的bash文件:

------------------------
#!/bin/sh
for i in `more userlist.txt `
do
echo $i
adduser $i
done
---------------------------

保存文件为useradd.sh。 运行该脚本文件:

--------------------
[lax@liulantao-com ~]# sh useradd.sh
---------------------

This will add all the users to the system. Now we have to change the passwords. Let’s say we want username123 as password. So for user nayeem the password will be nayeem123, rubi123 for user rubi and so on. 结果是添加了所有用户名到系统中。现在必须修改密码了。 假设我们用使用username123为密码。比如rubi的密码将是rubi123,依此类推。

Create another bash file as follows: 创建下面的脚本文件:

-------------------
#!/bin/sh
for i in `more userlist.txt `
do
echo $i
echo $i"123" | passwd –-stdin "$i"
echo; echo "User $username's password changed!"
done
--------------------

保存为userpasswd.sh。

-------------
[lax@liulantao-com ~]# sh userpasswd.sh
------------

Run the file. All the passwords are changed. 运行该文件。所有的密码被修改

转载本网站文章请保留这一行和以上所有文字,谢谢。