Create Users And Change Passwords With A Bash Script
Hi All,
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:
root@indiangnu.org:/home/arun# vi userlist.txt
Arun
Nishikant
Ali
Nishit
Ameya
Yogesh
Santosh
Save the file as userlist.txt. Now create the following bash file:
root@indiangnu.org:/home/arun# vi useradd
#!/bin/sh
# This script is useful for adding user
do
echo $i
adduser $i
done
Save the file and exit.
root@indiangnu.org:/home/arun# chmod 755 userlist.txt useradd
Now run the file :
root@indiangnu.org:/home/arun# ./useradd
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 arun the password will be arun123, ravi123 for user ravi and so on.
Create another bash file as follows:
root@indiangnu.org:/home/arun# vi userpass
#!/bin/sh
# This script is useful for changing user’s password
# Changing password using this script user must have to change password after next login
for i in `more userlist.txt`
do
echo $i
echo $i”123″ | passwd –stdin “$i”
echo; echo “User $i will be forced to change password on next login!”
done
Save the file and exit.
root@indiangnu.org:/home/arun# chmod 755 userpass
Run the file. All the passwords are changed.
The useradd and password changed one time bash script is available below
root@indiangnu.org:/home/arun# vi adduser
#!/bin/sh
# This user.sh script is useful for creating
# bulk number of user account with their password
# This script created by Ravi Bhure (date:14/01/2008)
# For further info please login http://indianGNU.org or
# mail ravi <at> indianGNU.org
#
for i in `more userlist.txt`
do
echo $i
adduser $i
echo $i”123″ | passwd –stdin “$i”
echo; echo “User $i’s password changed!”
echo; echo “User $i will be forced to change password on next login!”
done
changed the permission 755 “useradd” file.
Thank You
One Reply to “Create Users And Change Passwords With A Bash Script”
hi ravi……..
its nice yar………….
that means we added many users using this script.