Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

Connect to GitHub via SSH on Linux

If you’re tired of entering a username and password each time you push to a GitHub repository on the command line, a secure method for bypassig this is to set-up a connection using a set of SSH keys.

The SSH protocol allows a user to connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username and personal access token at each visit.

Part 1: Setting up the SSH keys

To set-up SSH keys on the local machine, enter the following command:

$ ssh-keygen -t ed25519-sk -C ""

Note: If the command fails and you receive the error invalid format or feature not supported, you may be using a hardware security key that does not support the Ed25519 algorithm. Enter the following command instead.

$ ssh-keygen -t ecdsa-sk -C ""

When you are prompted to “Enter a file in which to save the key,” press Enter to accept the default file location.

When you are prompted to type a passphrase, press Enter (you needn’t enter a value here). Press Enter a second time when asked to confirm the passphrase.

If successful, you should see output similar to this:

Your identification has been saved in /home/username/.ssh/id_ed25519.
Your public key has been saved in /home/username/.ssh/
The key fingerprint is:
The key's randomart image is:
+--[ED25519 256]--+
|     .. o.o..   .|
|        o oo+ B.+|
|         B . o.=+|
|        S + o.+.+|
|           o.o o.|
| .. o.  . o *.O o|
|   ...   . o * * |
|    +.      o + o|
|   .o+         . |

This means that your SSH key has been added to the ssh-agent.

Part 2: Save the SSH keys to GitHub

The administrator of the repository needs to unstall the SSH key. In GitHub, go to Settings > SSH & GPG Keys and click on “New SSH Key“.

Screen capture of GitHub website
The “Add New SSH Keys” page on GitHub

On the command line, enter the following command to view your public key:

cat /home/username/.ssh/

Copy the key and then return to the GitHub settings page.

Give the key a name and then paste the code into the “Key” text box. Press “Add SSH key”

Screen capture of GitHub website
Enter the SSH key into the “Key” text box and then press “Add SSH Key” to submit the public key to GitHub.

Part 3: Update the origin URI

Assuming your repository already has an origin URI using HTTP, remove the origin URL with the following command:

git remote remove origin

Next, add an SSH origin URL via the following command:

git remote add origin

You should now be able to push updates to GitHub repositories without having to enter a username/password combination on each occasion. To maintain account security, you can regularly review your SSH keys list in GitHub and revoke any keys that are invalid or have been compromised.

GutHub has additional information about SSH keys on their website.



No comments have yet been submitted. Be the first!

Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.