Title : Create Users And Change Passwords With A Bash Script 
Date : 2008-04-04 
Code : <p>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.</p>

<p>First create a file which contains all the user name. Something like 
this:</p>

<pre>nurealam
nayeem
mrahman
farid
rubi
sankar</pre>
<p>Save the file as <span class="system">userlist.txt</span>. Now 
create the following bash file:</p>
<pre>#!/bin/sh
for i in `more userlist.txt `
do
echo $i
adduser $i
done</pre>
<p>Save the file and exit.</p>
<p class="command">chmod 755 userlist.txt</p> 
<p>Now run the file:</p>
<p class="command">./userlist.txt</p> 
<p>This will add all the users to the system. Now we have to change the 
passwords. Let's say we want <span class="system">username123</span> as password. So for user <span class="system">nayeem</span> 
the password will be <span class="system">nayeem123</span>, <span class="system">rubi123</span> for user <span class="system">rubi</span> and so on.</p>
<p>Create another bash file as follows:</p>
<pre>#!/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</pre>
<p>Run the file. All the passwords are changed.</p> 
# securitydot.net Tue, 24 Nov 2009 22:00:05 +0000