DEV Community

Cover image for Setup Github SSH keys (for linux)
Aditya Raj
Aditya Raj

Posted on • Edited on

11

Setup Github SSH keys (for linux)

Step by step instruction to setup GitHub SSH Keys and connect you github account to your local linux machine to push changes in your github repository


Step 1: Check for Existing SSH Keys

Before generating a new SSH key pair, it's essential to check if you already have existing keys. Open your terminal and run the following command:

ls -al ~/.ssh
Enter fullscreen mode Exit fullscreen mode
  • Look for files named id_rsa (private key) and id_rsa.pub (public key). If they exist, you can skip the key generation step.

Step 2: Generate SSH Key Pair

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode
  • Replace "your_email@example.com" with the email address associated with your GitHub account.

  • Press Enter to accept the default file location and enter a passphrase if you want extra security.

Step 3: Start SSH Agent

eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode

Step 4: Add SSH Key to SSH Agent

  • Add your SSH private key to the SSH agent by running:
ssh-add ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode
  • If you set a passphrase during key generation, you'll need to enter it here.

Step 5: Add SSH Key to GitHub

Now, you need to add your SSH public key to your GitHub account. Display the contents of your public key by running:

cat ~/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

Copy the output and follow these steps :

  • Go to your GitHub account settings.
  • Navigate to "SSH and GPG keys".
  • Click on "New SSH key" or "Add SSH key".
  • Paste your SSH public key into the provided field and give it a title.
  • Click "Add SSH key".

Step 6: Test SSH Connection

To test if your SSH key is set up correctly, run the following command:

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

If everything is set up correctly, you'll see a message confirming your connection.


That's it! You've successfully set up SSH keys for your GitHub account on your Linux machine. Now you can clone, push, and pull repositories using SSH without the hassle of entering your credentials every time.

PS: When you will commit your changes for the first time, you will be asked to enter github configuration details like your name and email address.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay