Connect With Me In Facebook

Welcome to DefendHackers, If u want to Apply for a Blogroll as a Author , With h4ckfreak Mail me @ suren.click@gmail.com

Friday, October 21, 2011

Create a User Acc Using Bash Script in Linux




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.

 Before we jump in , For those who dont who kno what Bash file and how to create that ? click the link for refrence  Bash Guide

First create a file which contains all the user name. Something like this:
INFILTRATOR
SUREN GREY HAT
WILL MATHEWS
jOSHUSA
pHIL 
Risab Dang 




Save the file as userlist.txt. Now create the following bash file:


#!/bin/sh
for i in `more userlist.txt `
do
echo $i
adduser $i
done
Save the file and exit.
chmod 755 userlist.txt





ow run the file:
./userlist.txt
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 SUREN GREY HAT the password will be suren123, rubi123 for user rubi and so on.


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
Run the file. All the passwords are changed.


Thanks

2 comments:

Out of curiousity!! Why do I have to run the "userlist.txt" when it is obviously not a bash file but a simple text list of names file. Am I missing something here?
Clarify that please!
Thanks
Fatuh

I thought I should clarify this part for all of us the "newbies" out there.
Once you have saved the "userlist.txt" with the names u wanna add to the system, issue this command [chmod +x userlist.txt], that will make the file executable for the system not YOU! You don't run it.
The file you will run to add users is the bash file below:


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

Save this with a DIFFERENT NAME eg. [addingusers] in the same location as the "userlist.txt.
now go to the command line and change its mode like this [chmod +x addingusers].
Make sure the mode has changed to executable.
Now you are ready to add users....
Run the bash file addingusers like this.....[./addingusers]
Hope that help us the newbies to get started
Fatuh