Google Site SearchFN Site Search FN Blog Login FN Blog Login
Site Navigation:

A simple script on howto drop SSH keys on multiple machines.

by Daniel Owen on March 29, 2004

If you've been through my SSH howto, you may find this script useful as well.

I found myself in the predicament where i had about 50 machines I needed to put SSH keys on, so i could easily SCP files and remotely SSH commands on them. Since they didn't have keys already I didn't want to go through the lengthly process of scp everyone of them and then typing a password in each time. I looked through the SSH man file and saw no way to give SSH a password on the command line. The following script allowed me to type the password to the remote account on the machines i wanted to drop the keys on, only once. This script depending on the account and password is the same across the machines.

echo "Enter password for the "$USER" user."
stty -echo
stty echo
for i in $(cat $LIST);do
rsync -avW -e ssh $KEY $USER@$i:.ssh/authorized_keys
exit 0;

Since Rsync allows you to set the environment variable RSYNC_PASSWORD you can give rsync the password on the fly and it will send the file through ssh. The variable USER is the user you wish to put the key into, and KEY is the location of the public you want to use. LIST is the location of a flat text file with the IPS of the machines were dropping the keys on.