Linux

How to setup SSH in GitHub by example

One of the most secure ways to communicate over the public internet is by using SSH. This is why setting up an SSH key for GitHub is a top priority for users of this popular Git service.
Fortunately, the GitHub and SSH key configuration process is relatively straightforward on both Linux and Windows distributions.

Steps to set up GitHub SSH connections

To set up GitHub SSH keys and use them on both Ubuntu and Windows, follow these steps:

1 – Create a GitHub SSH key pair with the ssh-keygen command.
2-  Copy the value of the public SSH key to your clipboard.
3 – Log in to GitHub and navigate to your account settings.
4-  Click on the link for SSH and GPG keys.
5 – Click “Add Key” to register the public SSH key with your account.
6 – Name the key and paste the copied value into the text field.
7  -Save your changes.
8-  In your Git client, use the SSH-based GitHub URL to clone your repository.
Let’s go over each of these steps to set up GitHub SSH keys.

On both Ubuntu and Windows, the SSH keys you generate for GitHub must be placed in a folder named .ssh under the user’s home directory. To create your GitHub SSH key, perform the operation in this folder:

cd ~/.ssh

Use the ssh-keygen command to create GitHub SSH key pairs:

github@ubuntu:~/.ssh$ ssh-keygen -o -t rsa -C “[email protected]

The operation will prompt you to choose a location to save the public and private keys. Simply press Return to save them in the .ssh folder. This is where the SSH command will look for the keys when attempting to connect to a remote server.

The ssh-keygen command will also prompt you to protect your GitHub SSH key with an optional passphrase. You can leave the passphrase blank if you prefer, so simply press Return when prompted.

Connect to GitHub with SSH

 

Here is the full output you’ll see when you run the ssh-keygen command to create GitHub SSH keys:

github@ubuntu:~/.ssh$ ssh-keygen -o -t rsa -C “[email protected]”Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Your identification has been saved in /home/ubuntu/.ssh/id_rsa
Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub
The key fingerprint is: SHA256:g7RTuw9S+…
The key’s randomart image is:
+—[RSA 3072]—-+
| ..Bo+.+o.. |
|. *.= +E . . |
| …+ .. . . |
| +.. …+ o |
| B o ++ S |
| o . * = o + |
| o B.oo . |
| = oo + |
| .o .o . |
+—-[SHA256]—–+

The parameters used with the ssh-keygen command for GitHub are as follows:

The -o flag forces the tool to generate SSH keys in the OpenSSH format.
The -t flag specifies the type of SSH key to create.
The -C flag allows you to add comments as metadata at the end of the public key.

GitHub SSH Key Location

Once the key creation process is complete, the Ubuntu terminal displays a visually appealing piece of random art.

By default, the public and private GitHub SSH keys are saved in a folder named .ssh under the user’s home directory.

You will need to paste the contents of your public SSH key into GitHub. On Ubuntu, you can use the cat command to view the file’s contents in the terminal and then copy it. On Windows, simply open the file with a text editor to view and copy the contents.

github@ubuntu:~/.ssh$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCwrUzqtm
3K9YNI2WbXxkcfnHZgyW7/3WXghBbKndhbKbCR00JLfTHsK
Kaz17c4xIHQrw7u0GsPXai6pMtwMeVmXQH00L5hD0WE5Ioo

GitHub SSH Key Configuration

Next, configure the GitHub SSH key in your account settings. Log in to GitHub, go to your account settings, and find the link labeled “SSH and GPG keys.” Click on this link to add a new SSH key. Provide a unique name for the key and paste the value of the public SSH key you copied earlier.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button