SIMPLE AUTO SSH LOGIN TO REMOTE SERVERS WITHOUT PASSWORD

First you’ll need to generate your local public key. This is the public end of a local public / private pair that you’ll share with the remote machine to identify you.

This guide was written for CentOS / RHEL with caveats for Ubuntu.

ssh-keygen -t rsa (on your local machine)

NB> For Ubuntu you don’t need to specify the -t

Second you’ll need to copy this key to the remote machine using a command such as:

scp ~/.ssh/id_rsa.pub user@yourserver.com:

Lastly, log into the remote machine via ssh (using your password for the last time!) and use this command to add the newly generated key to the list of authenticated keys:

cat id_dsa.pub >> .ssh/authorized_keys

You’ll also probably want to delete the original key as well.

rm id_dsa.pub

Finally, change file permissions on this file to 600.

chmod 600 .ssh/authorized_keys

NB> For Ubuntu you will have to change the .ssh directory permissions to 700.

chmod 700 ~/.ssh

 

Further Reading