Monday, October 4, 2010

Adding User in Linux with Script

Create a File contains the username on each line. (userlist.txt)


#ADD USER


for i in `more userlist.txt `

do
echo $i
adduser $i
done


Remove shadow  file and create it again using 


  pwconv


That utility will reconcile all of the user accounts listed in the passwd file with the shadow file entries. Then you can use the passwd utility to create a passwd for the new user account.

#CHANGE THE PASSWORD

for i in `more userlist.txt `
do
echo $i
echo $i"123" | passwd –-stdin "$i"
echo; echo "User $username’s password changed!"
done

#FORCE TO CHANGE PASSWORD AT FIRST LOGIN

for i in `more userlist.txt `
do
echo $i
echo $i"123" | chage -d 0 --stdin "$i"
echo; echo "User $username’s password changed!"
done

No comments: