Operating System - HP-UX
1833589 Members
3751 Online
110061 Solutions
New Discussion

How to change password remotely?

 
SOLVED
Go to solution
Boudewijn
Occasional Contributor

How to change password remotely?

Hi,

I need to add an account to about 200 servers. Ofcourse i am doing this with a script.
But how do you set the password for all these accounts?

It is not possible with useradd. The command passwd can only be used locally.
Is there any way except for editing the passwd file on these servers to change the password?

Boudewijn
1 REPLY 1
Robin Wakefield
Honored Contributor
Solution

Re: How to change password remotely?

Hi Boudewijn,

I use the following script to change the root password. For safety/simplicity, I rcp the script across to all servers. Obviously, you should change "root" and uid=0/gid=3 to your new username/uid/gid (assuming it's the same on all servers).

Change the password on one server to get the encrypted string, then run this script everywhere using the encrypted password as the argument. You can do this with a simple loop:

for host in list_of_hosts ; do
change_passwd passwd-string
done

The script ensures that the string doesn't contain a "/", otherwise sed will fail and you'll be left with no passwd file!!

I would test/run it on a server where you already have a root login, just in case...That way you'll be confident it all works as you want.

===========================================
#!/bin/ksh

# Change root passwd
if [ $# -ne 1 ] ; then
echo Syntax: change_passwd {encrypted passwd string}
exit 1
fi
echo $1 | grep -q /
if [ $? -eq 0 ] ; then
echo The password string must not contain a slash
exit 1
fi
cp /etc/passwd /etc/passwd.old
if [ $? -eq 0 ] ; then
sed -e "s/^root:.*:0:.:/root:$1:0:3:/" /etc/passwd.old > /etc/passwd
chmod 444 /etc/passwd
chown root:sys /etc/passwd
else
echo copy failed
fi
===========================================

Rgds, Robin.