How to Create Key Pair for Github

- 2 mins read

Today, I’m diving into the process of creating an SSH key-pair to authenticate with GitHub. While there are plenty of fantastic guides out there on this topic, I’m writing this to solidify my understanding and share my journey.

Why bother with SSH keys for GitHub authentication? Well, let me tell you. GitHub offers two main authentication methods: using your username and password, or employing SSH keys. Personally, I’m not a huge fan of the former, so I always opt for SSH keys whenever I’m working with repositories.

So, what’s the big deal with SSH keys? They provide a more secure and convenient way to interact with GitHub. Instead of constantly entering your username and password, SSH keys offer a streamlined and safer authentication process. Once set up, you can seamlessly pull, push, and interact with repositories without the hassle of repeatedly typing in your credentials.

Main: A programmer with keys

Now, let’s get down to business. Here’s a step-by-step guide on how to create an SSH key and configure it with GitHub.

ssh-keygen is an awesome Unix tool that helps us to generate ssh-keypairs. We are going to generate one using ED25519 algorithm by executing the following command:

ssh-keygen -t ed25519 -C "<your_email_here>"

Or you can opt to use RSA algorithm after reading ED25519 vs RSA by executing the following command:

ssh-keygen -t rsa -C "<your_email_here>"

How do we verify that the operation is successful? Simply execute the following command:

tree ~/.ssh/

It would print the tree structure of the .ssh directory. An example is shown below.

Image 1: Tree structure of .ssh directory in my local machine

Now, we configure the newly created key in Github by going to Settings -> SSH and GPG Keys. Click on New SSH key button and a popup would appear as shown below.

Image 2: New SSH key screen

Title is a text value that is going to be used for identification. The pattern that I use for naming keys is: <cloud_name or localhost>_environment

After that simply put the contents of id_rsa.pub file in the Key section.

Note: The file id_rsa contains sensitive information. Please do NOT share with anyone.

That’s it! Happy Coding :