Setting Up SSH for GitHub: A Step-by-Step Guide

Divye JainDivye Jain
2 min read

This guide will walk you through the process of generating, adding, and using an SSH key for GitHub.

1. Generate Your SSH Key

First, you need to generate an SSH key. Open your terminal and run the following command, replacing with your actual email:

ssh-keygen -t rsa -b 4096 -C "your email"

When prompted, press Enter to accept the default file name and location. If desired, set a passphrase for extra security.

2. Start the SSH Agent

Once your key is generated, start the SSH agent in the background:

eval "$(ssh-agent -s)"

3. Add Your SSH Key to the SSH Agent

Next, add your private SSH key to the SSH agent:

ssh-add ~/.ssh/id_rsa

4. Copy Your SSH Key

Copy your newly generated SSH key to your clipboard using:

cat ~/.ssh/id_rsa.pub

5. Add the SSH Key to Your GitHub Account

Now, add your SSH key to GitHub:

  1. Log into your GitHub account.

  2. Select Settings

  3. In the left sidebar, choose SSH and GPG keys.

  4. Click New SSH key or Add SSH key.

  5. Enter a descriptive title and paste your copied SSH key.

  6. Click Add SSH key to save it.

6. Verify Your SSH Connection

To confirm that everything is set up correctly, run:

ssh -T git@github.com

If the setup is successful, you should see a message confirming authentication.

Wrapping Up

Congratulations! You’ve successfully set up SSH authentication for GitHub. From now on, you can securely push and pull repositories without entering your password repeatedly. Happy coding!


If you found this guide helpful, share it with fellow developers and let us know in the comments if you have any questions!

0
Subscribe to my newsletter

Read articles from Divye Jain directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Divye Jain
Divye Jain