Operating System - HP-UX
1834637 Members
2634 Online
110069 Solutions
New Discussion

setting users passwords in batch

 
SOLVED
Go to solution
Klaas D. Eenkhoorn
Regular Advisor

setting users passwords in batch

All,

How can i set, in batch, the password of a user ? (aprox. 300 accounts)
Probably there will be a existing thread about this subject but i can't find it.

Can somone help ?

Kl@@s
10 REPLIES 10
Pete Randall
Outstanding Contributor
Solution

Re: setting users passwords in batch

Oliver Charni
Trusted Contributor

Re: setting users passwords in batch

Hi!

Im not 100% sure but I think you cant set password in batchmode. What we are doing is we use sed to modify the /etc/passwd File with pregenerated hashes.
if it smell's funny on the outside, it's worse on the inside
Massimo Bianchi
Honored Contributor

Re: setting users passwords in batch

One way could be to write a script to be run as root, like the following.

I assume in the file list.txt there are entry in the form:

user1 password1
user2 password2

and so on..


########SCRIPT##############

while read USER PASSWORD
do

passwd $USER << EOF
$PASSWORD
$PASSWORD
EOF
done < list.txt

########END###################

HTH,
Massimo
John Carr_2
Honored Contributor

Re: setting users passwords in batch

Hi

I dont have my script to hand but i can explain how i did this.

I changed the pasword on account ourdefault then using grep took the encrypted password from the passwd file then using sed and awk applied it to a new passwd.new file and copied old password file to saved one and new one became real.

John.
RAC_1
Honored Contributor

Re: setting users passwords in batch

You can use expect for that.

As crude method you can do as follows.

I assume you have list of these users in a file.

for i in `cat file`
do
/usr/sam/lbin/usermod.sam -p "" $i
done

-p option on usermod is password. In above case it will set null password for all users.


Now you can modify this script further.


for i in `cat file`
do
/usr/sam/lbin/usermod.sam -p "`echo $i|makekey" $i
done

There is no substitute to HARDWORK
Stuart Urquhart
Frequent Advisor

Re: setting users passwords in batch

Passwd does something funny with stdin so you can't use a here docuemnt so it's Expect or http://hpux.connect.org.uk/hppd/hpux/Sysadmin/npasswd-1.2.4/ says it can do it via a pipe.
John Carr_2
Honored Contributor

Re: setting users passwords in batch

make sure you backup your passwd file before you do anything and have a session open as root when finished and test through another session. If you wreck the passwd file accidentally you cn live to regret it.

john.
Klaas D. Eenkhoorn
Regular Advisor

Re: setting users passwords in batch

Okeee,
One lesson learned allready . . .
If you modify accounts by batch give the system time to change the password file.
If not, you suddenly miss userid's !!!!

Gone, zip , away !!! :`-(

So use sleep after every command.
And keep a copy of the password file . . .

Yes yes yes i did that !!!!

By the way the last option, using sam to change the password, worked fine for me.

Kl@@s
Klaas D. Eenkhoorn
Regular Advisor

Re: setting users passwords in batch

Ps.

HERE document scripting does not work with passwd.
Tried it and failed . . .

Kl@@s