The script automatically pushes your SSH private key to the server specified so you can have automatic SSH,scp and sftp authentication. If you don’t have a key the script will generate one for you, also this script assumes that the user running the script has a home directory on the remote host. Should note that this script will only push the RSA encrypted key.
The Script
#!/bin/bash
# say: ./ssh_script.sh hostname
# Uploads your id_rsa.pub to the specified host, wrapped for readability
if [ ! -r ${HOME}/.ssh/id_rsa.pub ];then
ssh-keygen -b 2048 -t rsa
fi
# Append to the copy on the remote server
cat ~/.ssh/id_rsa.pub | ssh ${USER}@$1 “cat – >> .ssh/authorized_keys”
if [ $? -eq 0 ]; then
echo “Success”
fi
save the script say as ssh_script.sh and execute it ./ssh_script.sh hostname