When working with a large number of computers I am huge fan of certificate-based logins. If you setup your accounts this way you don’t have the problem of remembering passwords and having to enter them each time you login to those machines. The other plus is you can script out starting, stop, updating the services on those machines.
To enable this you need to generate the private and public key pair, this is done through the command “ssh-keygen –t rsa”. When you are running the command it will ask some questions. I normally use the default for where the files are stored (~/.ssh). For the passphrase I also tend to leave this blank – we are talking about enabling scripting across multiple computers here after all.
Once ssh-keygen completes the ~/.ssh directory will contain two files id_rsa (private) and id_rsa.pub (public). The text that is in the public key file gets copied into other computers ~/.ssh/authorized_keys file. This will allow the two accounts to be trusted.
Here is were I normally cheat a little when working with virtualized environments. I just copy the id_rsa.pub file to authorized_keys. This way when I clone the image everything is ready to go.
Now that we have setup our certificate based logins here is example script. This script will simultaneously login to all of the machine defined in the HOST variable and kills all of the java processes. A pretty handy script for development.
export SSH_USERNAME=cblack
export HOSTS="a.vmware.com b. vmware.com c. vmware.com d. vmware.com"
for curr_host in ${HOSTS}
do
ssh ${SSH_USERNAME}@${curr_host} "pkill -9 java" &
done
wait
Enjoy and happy scripting.