Thursday, September 10, 2009

Create Users And Change Passwords With A Bash Script

These two scripts are very important for the system admin who regularly works with mail servers and somehow forgets to backup his system username and password! Let’s say somehow we lost the usernames and passwords of the mail server. In this case the admin has to manually create all the users and then change the passwords for all the users. Tedious job. Let’s make our life easier.
First create a file which contains all the user name. Something like this:
Save the file as userlist.txt. Now create the following bash file:
for i in `more userlist.txt `
echo $i
adduser $i
Save the file and exit.
chmod 755 userlist.txt
Now run the file:
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.
Create another bash file as follows:
for i in `more userlist.txt `
echo $i
echo $i"123" | passwd –-stdin "$i"
echo; echo "User $username’s password changed!"
Run the file. All the passwords are changed.

No comments:

Post a Comment

tag ur valuable ideas below