Home / Command Line / SSH automatic login assistance script

SSH automatic login assistance script

Command Line 0

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




# 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


# 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”


save the script say as  ssh_script.sh and execute it ./ssh_script.sh hostname

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Previous Post

    Virtuozzo glibc-dummy-centos-4 Error (1)

    Next Post

    SSH Authorized Keys Automatic Login