Refer: https://gist.github.com/slowkow/8798394
The hostname of your remote server.
host=myserver.com
Create this folder if it does not exist: ~/.ssh
mkdir ~/.ssh
Set the correct permissions (required)
chmod 700 ~/.ssh
Generate an RSA key pair for identification with the remote server
ssh-keygen -t rsa
Copy your public key to the remote server
cat ~/.ssh/id_rsa.pub | ssh $host 'cat >> ~/.ssh/authorized_keys'
ssh is very strict about correct permissions, let's not change home folder persmissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
At this point, you can connect to your server without typing a password:
ssh username@myserver.com
