SSH keys are a pair of public and private keys that are used to establish an encrypted connection using SSH. In order to utilize SSH we’ll need to create a new pair of keys. By the end of this guide you’ll be able to SSH into your server by inputting a simple command like ssh myserver.
1. Create a new pair of keys by using: ssh-keygen -C "insert any comment here"
2. Append the contents of the public key into authorized_keys located at ~/.ssh/authorized_keys
3. Copy the new private key or its contents into a new file in your local machine.
4. Set read and write permissions of private key to owner only by using chmod 600 <private key>
5. You can now SSH by using ssh <username>@<host> -i <private key>
6. (Optional) Having to input the whole command every time can be tedious. We can simplify this command by creating a config file inside ~/.ssh/config which we can use to reference our remote server in the future. Inside the config file create and save a template similar to the following, where “myserver” can be any name you want:
Host myserver
HostName <host>
User <username>
IdentityFile <private key directory>
7. You can now SSH into your server by using ssh myserver!
Sources
Oracle Docs – Generate an SSH Key Pair
freeCodeCamp – “The Ultimate Guide to SSH – Setting Up SSH Keys”

Leave a Reply