sshpass – less secure, convienent for non-keyed scriptings…

apt-get install sshpass

or

http://sourceforge.net/projects/sshpass/files/latest/download

Example script…

#!/bin/bash
user=jjest
path=”/home/tso/$user/.ssh”
file=$(cat /home/$user/.ssh/id_rsa.pub)
for server in $(ssh ls “cat ./configs/groups/ls.cfg” | grep mcis | awk ‘{print $1}’ | grep -vw ‘rw’ | grep -vw ‘esx’ | grep -vw ‘unix’ | sort); do
sshpass -f ~/.pwd ssh -o NumberOfPasswordPrompts=1 -o ConnectTimeOut=1 -o StrictHostKeyChecking=no $server “exit” 2> /dev/null
if [ $? = ‘0’ ]; then
sshpass -f ~/.pwd ssh -o NumberOfPasswordPrompts=1 -o ConnectTimeOut=3 -o StrictHostKeyChecking=no $server “mkdir -p $path”
sshpass -f ~/.pwd ssh -o NumberOfPasswordPrompts=1 -o ConnectTimeOut=3 -o StrictHostKeyChecking=no $server “echo $file > $path/authorized_keys”
echo “$server – Key copied!”
elif [ $? != ‘0’ ]; then
echo “$server – host could not be reached, no account or wrong password!”
fi
done