How To: Create SSH Key


What is an SSH Key?

SSH Keys are an easy and secure way for computers to identify themselves when trying to establish a connection to a third party. Using SSH is more secure than just using a password alone as passwords 1) need to be sent over a network which makes them susceptible to eavesdropping and 2) they can be cracked by brute force attacks. When using an SSH key it is nearly impossible for it to be cracked by a brute force attack due to their complexity. Additionally, SSH keys are never actually transmitted over a network.

When a user creates an SSH key pair, a public and private key are both created. The way it works is let’s say your client machine initiates a request to access a server. The server then sends back an encrypted message using your public key that can only be decrypted by your paired private key. Therefore in order for the connection between the client and server to be established, the private key must be able to decrypt the encrypted message that was sent from the server using your public key.

How To: Create SSH Key

Follow these steps in order to generate and start using your SSH key pair.

Step 1: Make Sure you Don’t Already Have an SSH Key

Before creating your SSH key, you should first check to make sure you haven’t already created one in the past. This can be done by using the following command:

cd ~/.ssh

You should look for a pair of files named and id_rsa. These are known as your public and private keys respectively. If you don’t see these files or don’t even have a .ssh directory then you can move on to the next step.

Step 2: Create SSH Key

To create your SSH Key, run the following command:

ssh-keygen -t rsa

From here you will be given the option to enter a passphrase to access your private key. Implement this at your own discretion. Just know that if by chance an unauthorized user tries to access your private key they will need to enter your passphrase if you set one (making it more difficult for them to access your private key). The downside to this is that you will need to enter your passphrase every time you use the key pair. Once this step is complete, your keys will be stored in your home/user/.ssh directory.

Step 3: Add Your Private Key to Your System

Make sure your private key is added to your system by running the following:

ssh-add /path/to/your/private.key

Step 4: View Your Public Key

You are now ready to copy your public key to a service that you would like to connect to via SSH. To view your public key, use the following command within the .ssh directory:


This will display your public key which you can then copy and paste to your desired destination.

That’s it! You now have a public and private key generated on your local machine and are able to use them to connect to third party services quickly and securely.

One Comment

  1. Sean

    Just a FYI to those who are also not “server admins”…

    If you attempt to add your private key (id_rsa) and you get “Could not open a connection to your authentication agent.” you may need to start the ssh agent:

    > eval `ssh-agent -s`
    Agent pid 12345

    Then run the ssh-add command
    > ssh-add /home/user/.ssh/id_rsa
    Identity added: /home/user/.ssh/id_rsa (/home/user/.ssh/id_rsa)


Leave A Comment?