Yaky's

SSH Key Authentication


SSH key authentication allows you to securely connect from your main Linux machine to a remote Linux machine without typing a password.

Generate SSH key pair

You only need to do this once (unless you reinstall the OS or delete the keys intentionally).
On your main machine:
ssh-keygen
Choose default location.
Do not set a passphrase.
This creates a key pair in ~/.ssh/

Copy SSH key to the remote machine:

Easy way, on your main machine:
ssh-copy-id username@remote.host
Enter the password for username on the remote machine.

Alternative way: (if SSH does not work, for example)
Copy the content of ~/.ssh/id_rsa.pub from your main machine:
cat ~/.ssh/id_rsa.pub
On the remote machine, create the SSH authorized keys file (if it does not exist)
mkdir ~/.ssh/
chmod 700 ~/.ssh  # this is important.
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys  #this is important.
Copy the content of ~/.ssh/id_rsa.pub from your main machine to ~/.ssh/authorized_keys on the remote machine.

The key is now copied to the remote machine.

Log into the remote machine

ssh username@remote.host

Original source on DigitalOcean