How to Generate a new SSH Key | Check for Existing SSH Keys

We have already seen How to Clone a Repository using HTTPS and SSH before, we will see how to generate a new SSH key in this post.

When you are dealing with multiple email accounts, you might be required to create a new SSH Key. Also, in a multiple project environment kind of setup where you wish to have a separate key pair for security purposes, generating a new SSH key becomes important.

key meme

Ooh! That looks painful. That joke hurt.

How to Check for Existing SSH Keys

The first thing that you need to do is check for available SSH keys. You know, primarily, because sometimes you already have a key, but you are not sure. To do that you can use the following command in your git bash terminal.

ls -al ~/.ssh

Once done, press enter.

If you get any of the following results:

  • id_rsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub

That means you already have a public SSH key.

list existing keys command

I did the above little exercise and got myself id_rsa.pub in the result, that means I already have a public and private key pair.

But what if you don’t want to use that pair to connect to GitHub? You can always a create a new one!

Steps on How to Generate a new SSH Key

Alright, the following steps are when you don’t have an SSH key and you want to create a new one.

Step 1: Go ahead and type the following in your git bash terminal:

$ ssh-keygen -t ed25519 -C "your_email@example.com"

I will show you how I have done it:

default location for ssh key

Step 2: Press Enter and it will ask you to enter the location of the file where you want to store the key. You can simply press enter.

Doing that will save the key in the default location. As you can see C:/Users/psingh/ etc. is my default location.

Step 3: Next you will be asked to enter a passphrase. Type a passphrase and make sure you remember it because you will be asked to enter this whenever connecting to GitHub.

how to generate a new SSH key final image

Press Enter.

Step 4: Retype the passphrase in the next line and press Enter again.

You will see the following message,

Your identification has been saved in your <default location>id_ed25519
Your public key has been saved in your <default location> id_ed25519.pub

The key fingerprint will be printed next. It will be soon followed by a randomart image as shown in the figure above.

The job is only half complete, since you now have to copy your SSH key to your GitHub account settings.

We will talk about how to add a new SSH key to GitHub account in our next tutorial.

Scottshak

Poet. Author. Blogger. Screenwriter. Director. Editor. Software Engineer. Author of "Songs of a Ruin" and proud owner of four websites and two production houses. Also, one of the geekiest Test Automation Engineers based in Ahmedabad.

You may also like...

1 Response

  1. April 11, 2021

    […] am assuming you already have generated your new SSH Key before we learn how to add a new SSH key to GitHub today. You would need the passphrase that you […]

Leave a Reply