Shell Script to add users and corresponding password automatically

 Shell Script to add users and corresponding password automatically

In this post we are going to see about how to add users and their corresponding password automatically using linux shell script. Previously we have seen about some scripting tricks it contains more widely used scripting options.

Okay! Lets see how to add users and their corresponding password automatically using linux shell script.

. . .List of Users to be Added . . .
#cat list
ravi
deepak

. . .Script to automate User and their Password Adding . . .
#vim auto.sh
#!bin/bash
cat /dev/urandom | tr -cd “a-zA-Z0-91234567890-=\`” | fold -w 9 | head -n 2 > pass
cp pass check
u=`cat list`
for j in $u
do
useradd $j
echo “User $j Added”
echo “==================================”
done
for i in $u
do
echo “User Name is :$i”
p=`cat pass`
echo “$p” | passwd –stdin “$i”
sed -i ‘1d’ /home/rajm/script/blog/auto/pass
#sed -i ‘1d’ $p
echo “User $i ’s password changed!”
echo “==============================”
done

. . .Give permisson and run the script. . .
#chmod +x auto.sh
sh auto.sh
User ravi Added
==================================
User deepak Added
==================================
User Name is :ravi
Changing password for user ravi.
passwd: all authentication tokens updated successfully.
User ravi ’s password changed!
==============================
User Name is :deepak
Changing password for user deepak.
passwd: all authentication tokens updated successfully.
User deepak ’s password changed!
==============================

. . .The File check used to check the password. . . .
#cat check
5<YX<jR0I
=tAn`0;mt




Leave a Reply

Your email address will not be published. Required fields are marked *