Understanding SSH Keys

SSH is the most common way of connecting to remove Linux Server. It stands for Secure Shell. It provide a safe and secure way of executing commands, making changes and configuring service remotely. SSH connecting is implemented using client-server model. For a client machine to connect to a remote machine using SSH, SSH daemon must be running on the remote machine.

Clients generally authenticate either using passwords or by SSH Keys. SSH keys provides a more secure way of logging into a virtual private server using SSH. SSH keys are nearly impossible to decipher by brute force alone.

SSH keys are a matching set of cryptographic keys. Each set contains a public and private key. To authenticate using SSH keys, you place the public key on any server and then unlock it by connecting with the private key.

Generating SSH Key Pair

ssh-keygen -t rsa

Copy Public Key

ssh-copy-id user@123.45.67.89

Alternatively,

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

Note - Generally when you spin up a server, you can embed your public key in your new server.

Generate Public Key from Private Key

Option -y outputs the public key

ssh-keygen -y -f private-key > public-key

# Example
ssh-keygen -y -f pin-ost.pem > art.pub

Reference

https://www.digitalocean.com/community/tutorials/ssh-essentials-working-with-ssh-servers-clients-and-keys