SSH Key Setup Guide
If you're using Windows, you need to use PowerShell for these commands to work. Linux and maybe Mac should work with these as well.
Check if you have an SSH key already:
ls ~/.ssh
Otherwise, generate a new key:
ssh-keygen -t rsa -b 4096 -C "email@email.com"
The email part is optional because it's just a comment used to identify yourself. You can also change rsa
to a different encryption if needed.
Display the public key:
cat ~/.ssh/id_rsa.pub
Copy the public key to your clipboard. Now SSH into your server:
ssh username@server.name
Run these commands on the server:
mkdir -p ~/.ssh
vim ~/.ssh/authorized_keys
Paste the key you copied earlier onto the next available line in the file. Since it's Vim, you would probably press
Shift+G
to go to the end of the page, then i
to enter insert mode, then Ctrl+Shift+V
to paste the text.
Then press Esc
and type :wq
to save and quit.
This last step is probably optional, but you can also set the permissions for the SSH folder:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Just for fun, this is what the permissions mean:
7 111 read, write, execute (owner)
0 000 no access (group)
0 000 no access (others)
6 110 read, write (owner)
0 000 no access (group)
0 000 no access (others)