Operating System - HP-UX
1833323 Members
2868 Online
110051 Solutions
New Discussion

changing password in a script

 
Nisar Ahmad
Regular Advisor

changing password in a script

Hi There

I want to change passwds for all users in a do loop to a same string using a script.

Any idea please

Thanks in advance

Nisar
3 REPLIES 3
Rajeev  Shukla
Honored Contributor

Re: changing password in a script

You can do that by using /usr/sam/lbin/usermod.sam -p login_name
The password here is the encrypted password which you can generate by writing a small c program or other option is to ass a dummy user and assign the password that you want to say "test123" you have the encrypted password in the passwd field in /etc/passwd for that user.
Now take that string and write a while loop
while read i
do
/usr/sam/lbin/usermod.sam -p $i
done
where /tmp/1 contains all the users whose password you want to set.

Cheers
Rajeev
Michael Steele_2
Honored Contributor

Re: changing password in a script

a) you can use this command to fill you file of accounts:

cat /etc/passwd | awk -F : '{ print $1 }' > output.file

b) Or try extending the command with passwd -f. With passwd -f you force each user to change the password at next login.

cat /output.file | passwd -f (* wild guess *)

Use pwck to verify /etc/passwd.

And copy your /etc/passwd file before starting.



http://docs.hp.com/en/B2355-60103/passwd.1.html
Support Fatherhood - Stop Family Law
doug hosking
Esteemed Contributor

Re: changing password in a script

Michael, your 'awk' approach needs to consider whether the system is configured to use NIS, netgroups, other repositories, etc. There may be /etc/passwd entries starting with '+' for example.

Also, 'passwd -f' requires a user name, as noted on the man page and usage message for passwd.

$ echo foo | passwd -f
Usage:
passwd [name]
passwd -r files [-F files] [name]
passwd -r files [-e [shell]] [-gh] [name]
passwd -r files -s [-a]
passwd -r files -s [name]
passwd -r files [-d|-l] [-f] [-n min] [-w warn] [-x max] name
passwd -r nis [-e [shell]] [-gh] [name]
passwd -r dce [-e [shell]] [-gh] [name]

Tools such as 'expect' (available at expect.nist.gov) can be helpful for such tasks. http://en.wikipedia.org/wiki/Expect has some examples of automating ftp and telnet sessions.

http://rodopi.floydrussell.com/events.html has a 'password script' section that shows an example of an expect script for performing such tasks. (I know nothing of this site; it just happened to show a simple example of such a script.)