Cheatsheet: SSH Key Pairs

Description

Information and useful commands for SSH Key pair generation and usage.

Debian Distros

The following steps have been tested on Ubuntu 16.04. Should work in any Debian distro

Generate key pair.

ssh-keygen
The keys are at ~/.ssh

View public key

cat ~/.ssh/id_rsa.pub

Add public key to remote server

Create new user (if not already)

sudo adduser username
sudo usermod -aG sudo username

Change to new user

su - username

Add the public key

sudo nano ~/.ssh/authorized_keys
Paste the public key and save

OR

ssh-copy-id username@203.0.113.0 from your local machine
If you get Permission denied (publickey), you must enable password authentication in your remote machine. To do so, login as root and:
sudo nano /etc/ssh/sshd_config

change PasswordAuthentication no to PasswordAuthentication yes

restart the service: sudo systemctl restart sshd

Enter again ssh-copy-id username@203.0.113.0 from your local machine

change PasswordAuthentication yes back to PasswordAuthentication no

Windows

The following steps have been tested on Windows 10.

Generate key pair.

Open Powershell
ssh-keygen
The keys are at C:/Users/YourUserName/.ssh

Subscribe to Pandor1an's Den