Instruction for Adding an SSH Key to your Github Account (Ubuntu 20.04.3 LTS)

Teddddd
NTUST-AIVC
Published in
4 min readMar 23, 2022

Co-Author: Y. S. Huang, a master’s student studying AIVC, likes open-source.
If you are interested, go to check my Github!

Let’s have a quick explanation of SSH key!

SSH(Secure Shell Protocol) is one of the approaches to encrypt our data, a common way used to connect to remote servers. But how does SSH work? and what are the differences with other methods? Let’s take a look!

The Schematic of SSH

The main idea of SSH is that use “Private Key” and “Public Key” to encrypt data. Assume that A wants to transmit data to B. The operating sequence is illustrated below:

  1. A produces a digital signature by its own private key. That can help B to identify the source of the data.
  2. A use B's public key to encrypt its own message. Therefore, we can only decrypt by B’s private key
  3. After the operations above, messages of A are ready to send!
  4. When B receives the data, B will use its private key to interpret the message and A’s public key to distinguish the digital signature.

Start to set up the SSH key!

Let’s use an example to easier to understand all processes:

$ ssh-keygen -t ed25519 -C “yourmail@mail.com

First, you need to generate your own SSH key. Entering ssh-keygen commend, you will see this information below:

Generating public/private ed25519 key pair. 
Enter file in which to save the key (/home/name/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

In the second row, you can enter the path on which you want to place the keys. If you enter nothing, the system will just use the default path indicated in the brackets.

The next two rows are for password setup. In the same case, you can left blank if you don’t need a password.

After generating the SSH key, you can check out the file we had set up.

$ cd .ssh
$ ls

If you generate the keys successfully, you will see two files: id_ed25519 and id_ed25519.pub(or the name you set). These two files are your private key and public key respectively.

To get your public key, clicking the file directly might not be useful. So you need to use this command. Just copy all of the coming words, and we will use it later.

$ cat ~/.ssh/id_ed25519.pub

Upload the SSH key to Github

First, we need to go to Github. And then press the inverted triangle on the top right.

Second, press the “SSH and GPG keys”. You will see the SSH key on the top of the page.

Third, click the “New SSH key”.

Finally, you can name the key in the “Title” sheet, and add the public key we just copied in the “Key ”sheet. Press “Add SSH key” when you are finished!

So far, we had set up the SSH key on Github. However, there are still some steps we need to finish.

Change the new protocol in your terminal

After you upload the SSH key to Github, you need to set SSH to a new connect protocol.

$ git remote set-url origin git@github.com:user_name/repo_name.git

The link can be found on your page of the repository.

Enjoy it!

You can try to use ssh-T git@github.com the command to check whether the SSH key was sent successfully or not.

$ ssh-T git@github.com
Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.

Finally, you can start your journey on using SSH key, a more convenient and safer way to operate Github!

--

--

Teddddd
NTUST-AIVC

A bachelor of NTUST EE who is learning Linux, Docker, CV, and ML.