Effortlessly Set Up SSH for GitHub on Ubuntu: A Complete Guide

Fredy Yudiawan
2 min readNov 30, 2023

--

Introduction:

Welcome to this step-by-step guide on setting up SSH for GitHub on your Ubuntu system. SSH (Secure Shell) is an essential tool for developers, providing a secure way to interact with remote servers. In this article, we’ll walk through the process of generating an SSH key, adding it to your GitHub account, and ensuring a seamless and secure connection.

Step 1: Opening Your Terminal

The first step is to open your terminal. You can do this by pressing Ctrl+Alt+T or searching for 'Terminal' in your applications menu. The terminal is where you will enter all the commands necessary for this setup.

Step 2: Checking for Existing SSH Keys

Before we create a new SSH key, it’s wise to check if you already have one. Type the following command in your terminal:

ls -al ~/.ssh

Look for files named id_rsa.pub, id_ecdsa.pub, id_ed25519.pub, etc. If you find an existing key and wish to use it, you can skip the next step. Otherwise, let's create a new one.

Step 3: Generating a New SSH Key

To generate a new SSH key, use the following command in your terminal. Remember to replace your_email@example.com with the email associated with your GitHub account:

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

For older systems that don’t support the Ed25519 algorithm, use:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

When prompted to “Enter a file in which to save the key,” just press Enter to use the default location.

Step 4: Adding Your SSH Key to the SSH Agent

First, start the SSH agent in the background:

eval "$(ssh-agent -s)"

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

ssh-add ~/.ssh/id_ed25519

Replace id_ed25519 with your key's filename if you used a different one.

Step 5: Adding SSH Key to Your GitHub Account

Now, you need to add your new SSH key to your GitHub account. Install xclip to easily copy the key to your clipboard:

sudo apt-get install xclip
xclip -sel clip < ~/.ssh/id_ed25519.pub

Alternatively, open the key file in a text editor and copy the contents manually.

cat ~/.ssh/id_ed25519.pub

Go to GitHub, navigate to Settings > SSH and GPG keys, and add a new SSH key. Paste your key into the field, give it a meaningful title, and save it.

Step 6: Testing Your SSH Connection

Finally, test your SSH connection to GitHub:

ssh -T git@github.com

If you see a message about authenticity, type ‘yes’ to continue. You should then receive a message confirming that you’ve successfully authenticated.

Conclusion:

You’ve successfully set up SSH for GitHub on your Ubuntu machine! This secure method of communication is vital for safely managing your repositories and code. If you encounter any issues, make sure to double-check each step for accuracy.

--

--