Using SSH with Git Hub

With GitHub being the most popular git based repository (but not the only one) I write this for GitHub. But the procedure is pretty much the same on other git repositories, with the differences being in the web interfaces. If you haven’t already, consider using SSH keys for accessing your git repositories. They provide a more secure authentication method than using passwords. Each of your computers can have a different key. If the keys were somehow compromised, you could revoke the key for that compromised computer without affecting the other computers.

To use get with SSH keys, you need a public/private key pair. To create a keypair, use the following command. Make sure that you use your own email address.

ssh-keygen -t ed25519 -C "user@domain.com"

After typing this command in, you’ll be asked to enter a key phrase for the key. This of this as the password. If you forget it, there is no way to recover it. The output from this command looks similar to the following.

Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\ThisUser/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\ThisUser/.ssh/id_ed25519.
Your public key has been saved in C:\Users\ThisUser/.ssh/id_ed25519.pub.
The key fingerprint is:
SHA256:9aglYQliSNTdn6AkDDAlchq+uC3lb43lg4yNgE8TG2s user@domain.com
The key's randomart image is:
+--[ED25519 256]--+
|=====...         |
|o...o.o.o.       |
|.. . = .+o..     |
|. +   .. ooo     |
|o===    X o .    |
|o==   .+++       |
|o=o= *  *        |
| .+.* +          |
|   ..  .         |
+----[SHA256]-----+

This creates two files named id_ed25519 and id_ed25519.pub. The file that ends with .pub is the public key and is shared with any entity that needs to authenticate you. The file without an extension is the private key. That is not to be shares. Open the .pub file and cop it’s contents to your clipboard. You are going to need it in a moment.

Login to github.com and go to your account settings. To get there, click on your profile icon in the upper-right corner, select settings. From the menus on the left, select SSH and GPG Keys. Here, your SSH public keys will be listed (if you have any). Select the option New SSH Key. You’ll need to enter a name for the key (here, I entered the name of the computer that the key is associated with) , select a Key Type (Choose Authentication Key), and paste the key into the text box. Select Add SSH Key to save the key. The view will refresh and show your new key in the list.

To use the key, after you’ve selected a git repository, in the clone option for the repository is the option to use an SSH key.

A git repository showing the SSH URL.
The SSH cloning option for a repository.

To clone, just use that URL as a parameter to the clone command.

git clone git@github.com:j2inet/CppAppBase.git

You’ll be prompted for the paraphrase. The cloning experience feels the same way as it does when using a password. If you didn’t set a paraphrase for your key, then you won’t be prompted for a password.

PS C:\shares\projects> git clone git@github.com:j2inet/CppAppBase.git
Cloning into 'CppAppBase'...
Enter passphrase for key '/c/Users/User/.ssh/id_ed25519':
remote: Enumerating objects: 594, done.
remote: Counting objects: 100% (100/100), done.
remote: Compressing objects: 100% (70/70), done.
remote: Total 594 (delta 40), reused 75 (delta 25), pack-reused 494 (from 1)
Receiving objects: 100% (594/594), 82.72 MiB | 3.43 MiB/s, done.
Resolving deltas: 100% (281/281), done.
PS C:\shares\projects>

Posts may contain products with affiliate links. When you make purchases using these links, we receive a small commission at no extra cost to you. Thank you for your support.

Mastodon: @j2inet@masto.ai
Instagram: @j2inet
Facebook: @j2inet
YouTube: @j2inet
Telegram: j2inet
Twitter: @j2inet

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.