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@

Alternatively, you can paste in the keys using SSH:

cat ~/.ssh/ | ssh user@ "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


Leave a Reply

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