Script to change password on linux servers over ssh Script to change password on linux servers over ssh shell shell

Script to change password on linux servers over ssh


The remote machine(s) do not need expect installed. You can install expect on a local workstation or VM (virtualbox) or whichever *nix box, and write a wrapper that calls this .ex (expect) script (there may be small changes from distro to distro, this tested on CentOS 5/6):

#!/usr/bin/expect -f# wrapper to make passwd(1) be non-interactive# username is passed as 1st arg, passwd as 2ndset username [lindex $argv 0]set password [lindex $argv 1]set serverid [lindex $argv 2]set newpassword [lindex $argv 3]spawn ssh $serverid passwdexpect "assword:"send "$password\r"expect "UNIX password:"send "$password\r"expect "password:"send "$newpassword\r"expect "password:"send "$newpassword\r"expect eof


You do not need root access to use passwd.

This shoud work just fine.

passwd <<EOFold passwordnew passwordnew passwordEOF


You should try pssh (parallel ssh at the same time).

cat>~/ssh-hosts<<EOFuser100@host-foouser200@host-baruser848@host-quxEOFpssh -h ~/pssh-hosts 'printf "%s\n" old_pass new_pass new_pass | passwd'