Posts Tagged: ‘scripts’

Changing password on multiple in an automated way using a bash script

August 31, 2012 Posted by admin

I was recently tasked with changing the root password on a hundred servers.

This action need to be done quickly and in an automated fashion.

As I was trying to figure out how to do this I remembered we had an ssh script user

that had sudo access. So I put together a text file consisting of all the ip’s

root@triplehelix ~$ for i in {1..100}; do echo "10.38.251.$i" >>servers.txt; done
root@triplehelix ~$ cat servers.txt


Next I created a script that I could run from the command line using my severs.txt file as input.


root@triplehelix ~$ cat changepw

for server in `cat servers.txt`; do
ssh -i ~/.ssh/id_rsa $server -l scriptuser ‘sudo passwd root< <EOF