PDA

View Full Version : [ubuntu] Changing user passwords



zyban03
February 13th, 2009, 11:31 PM
In a nutshell
I am trying to change a list of users passwords with a bash script. This link (http://www.howtoforge.com/user_password_creating_with_a_bash_script) was helpful but the password part doesn't work for me.
Is there a way to change a users password with just a single line. Or is there a way to send text back to the screen when it asks you to enter your new password?

Password Script
#!/bin/sh
for i in `more userlist.txt `
do
echo $i
echo $i"123" | passwd -stdin "$i"
done

Ubuntu Server 8.04

supersonicdarky
February 13th, 2009, 11:44 PM
#!/bin/bash
# 1st param - pswd
# 2nd param - text-file with usernames, one per line

if [ $# -lt 2 ]; then
echo "Usage: ./passwd.sh <passwd> <text file>"
exit
fi

for i in `cat $2`; do
echo "$i:$1"
yes "$1" | passwd "$i"
done

here you go

if you want, i can modify it to read a txt file that has both username and passwd on each line and then set the passwd accordingly

zyban03
February 14th, 2009, 07:40 PM
THANKS!
I will give that shot. I will just add the password expire line to the bottom and that should give all the new users I create a temp pass and then make them change it at first login. I will let you know my results.:P
Thanks Again!!

zyban03
February 15th, 2009, 12:29 PM
#!/bin/bash
# 1st param - pswd
# 2nd param - text-file with usernames, one per line

if [ $# -lt 2 ]; then
echo "Usage: ./passwd.sh <passwd> <text file>"
exit
fi

for i in `cat $2`; do
echo "$i:$1"
yes "$1" | passwd "$i"
done

here you go

if you want, i can modify it to read a txt file that has both username and passwd on each line and then set the passwd accordingly

I tried your code a couple of different ways and kept getting a line 14 syntax error which I couldn't figure out. However you did get me on the right track. I did some digging on alternative ways to change and re-wrote it like so


#!/bin/sh
for i in `more userlist.txt `
do
echo $i
echo $i:temp123 | chpasswd
passwd $i -e
echo; echo "User $i will be forced to change password on next login!"
done


Worked out like a champ!!
Thanks for your all your help.