How To Set Up SSH Keys

Step One—Create the RSA Key Pair

ssh-keygen -t rsa

Step Two—Store the Keys and Passphrase

Enter file in which to save the key (/home/demo/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):

Step Three—Copy the Public Key

ssh-copy-id user@123.45.56.78

Alternatively, you can paste in the keys using SSH:

cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"

Optional Step Four—Disable the Password for Root Login

sudo nano /etc/ssh/sshd_config

Within that file, find the line that includes PermitRootLogin and modify it to ensure that users can only connect with their SSH key:

PermitRootLogin without-password

Put the changes into effect:

reload ssh

Source: https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys–2

Leave a Reply

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