Monday, April 27, 2009

Changing Linux user's password with script

It is time consuming to change user’s password for many hosts, The expect language can be used to change password without typing password,the chpasswd tool in Linux is easier to use. chpasswd is from pwdutils RPM, it should be available to all Linux distributions.

#== Create the script to change password.

echo "root:newpasswd" | /usr/sbin/chpasswd 

$chmod +rx

#==Copy the script the remote-host and execute it
sudo is used because root ssh login is disabled, for unknown reason the temp file couldn't be deleted with sudo, so it is emptied instead

$scp -p remote-host:/tmp/
$ssh remote-host sudo '/tmp/;cat /dev/null>/tmp/;cat /tmp/'

No comments:

Post a Comment