GitHub: How to configure connection over SSH – Ubuntu 18.04

GitHub: How to configure connection over SSH – Ubuntu 18.04

Introduction

SSH (Secure shell) for standard communication protocols used in TCP / IP computer networks.

In this post, we’ll focus on configuring communication between our computer and the GitHub server using the SSH protocol.

Tworzenie pary kluczy RSA

First, create an RSA key pair – the public and private key. As we can see, the default path for keys is “/home/<user_name>/.ssh/“. When creating keys, we can protect them with an additional password (Enter passphrase). We can of course skip it by pressing Enter.

pawel@pawel:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/pawel/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/pawel/.ssh/id_rsa.
Your public key has been saved in /home/pawel/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:DLDvn4R61tr+xwNTOL4YDd+SVxonIMPSjPzLnvZ5MGo pawel@pawel
The key's randomart image is:
+---[RSA 2048]----+
|    .. =         |
|     o+ * .      |
|    . .o o o     |
|     . oo o + o  |
|      ..S* = *   |
|     . .+ @ +    |
|      oo.= X     |
|     .o+E...=    |
|    .o.==o+o .   |
+----[SHA256]-----+

Our keys are available in order:

  • Private key – in /home/pawel/.ssh/id_rsa
  • Public key – in /home/pawel/.ssh/id_rsa.pub

GitHub configuration

To add a public key to our GitHub account, please log in and go to: https://github.com/settings/keys

Then click the green “New SSH key” button.

In the next window, enter the title – here please enter the unique name of our connection, e.g. test_ssh_key_ubuntu.

In the Key field, paste your previously generated public key. To find out what it looks like, just use the “cat” command to display its contents in the console.

pawel@pawel:~$ cat /home/pawel/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0g6xgWHh6vKjitxD9wTTdhj2A0ZKfh09QsBdlgK9zh2wiQhfiQQWMau6YkkN993w7Dgn6HiOc8MikqxUf/xLfGkr36W7D7HIBKaKkNd/GresLzcv0NukATZQyoChjARoW3kUuPYhxL/wuTMfohSc6vbyl+jak34rG6pQzfZcvsZfGMUsaVQKNy2gUHhYS/yOWanKFf87QIap7Oy12+uZT229BSbrrSkdld4wdHS9/sVUu6ZdAQtdPGXqSdwyxSdQ+YSfbNyX1mrBFNsl0/A3QXA9+25K9Qj4gqVsIzCFzMnyEie3frrq3yzQ+OgYh81yIX4T3z/1JHGvx21nhvZKR pawel@pawel

We can now copy and paste it on the GitHub website. Click the “Add SSH Key” button.

We can now copy and paste it on the GitHub website. Click the “Add SSH Key” button.

Clone the repository using SSH

Now we can check if we are able to clone the GitHub repository using SSH. I will show you how to do this on your repository.

We enter the repository selected by, click “Clone” and select the “Use SSH” option.

We copy the generated link and then run the command in the console in the selected directory:

pawel@pawel:~$ git clone git@github.com:bigdata-etl/blog.git
Cloning into 'blog'...
The authenticity of host 'github.com (140.82.118.4)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,140.82.118.4' (RSA) to the list of known hosts.
remote: Enumerating objects: 4, done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 4
Receiving objects: 100% (4/4), 4.50 KiB | 4.50 MiB/s, done.

Summary

In this post, we went through creating the RSA key pair and configuring GitHub. Now you can easily and securely start managing your Git repository.

If you enjoyed this post please add the comment below or share this post on your Facebook, Twitter, LinkedIn or another social media webpage.
Thanks in advanced!

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu