You can use SSH keys to establish a secure connection between two computers. The steps below will walk you through generating an SSH key.
Step 1: Check for SSH keys
First, we need to check for existing ssh keys on your computer. Open up a terminal and run the following command to list the files in your .ssh directory:
Check the directory listing to see if you have a file named either id_rsa.pub or id_dsa.pub. If you don’t have either of those files proceed with step 2. Otherwise, you already have an existing key pair, and you do not need to do anything.
Step 2: Generate a new SSH key
To generate a new SSH key, enter the command below. We want the default settings so when asked to enter a file in which to save the key, just press enter, but do not omit setting a passphrase (a password) for the key.
ssh-keygen -t rsa -C "firstname.lastname@example.org"
Why do passphrases matter? It keeps your secret key part secret and prevent its usage in case some can copy it!
As a result you get something like:
# Your identification has been saved in \$HOME/.ssh/id_rsa.
# Your public key has been saved in \$HOME/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db email@example.com