Git is a distributed version control system designed to handle any size project quickly and efficiently. Git and GitHub are essential tools for developers. Most IT companies use GitHub to manage their small as well as large project. In this tutorial, we will learn about How to setup ssh key on GitHub and how we can generate and configure the SSH keys on GitHub.
There are other Git hosting services such as Bitbucket, GitLab, etc. But the most popular choice for the developers is GitHub. For each machine and server, we should use SSH keys for the secure connection.
- Linux-based operating systems like Ubuntu, CentOS, etc.
- Access of Root user or another user with Sudo privileges.
- Access to a GitHub Account.
For this tutorial, we are using Ubuntu 22.04 server. You guys can use any type of Linux based operating system. This tutorial will work for every Linux based operating system.
SSH stands for the Secure Shell. SSH keys are the access credential which is used in the SSH protocol. It enables secure access over the internet to access remote servers and devices.
SSH is widely used for the following functions:-
- To access remote systems
- To execute commands on remote servers or systems in a secure and encrypted environment.
- Secure remote delivery of software updates
- Secure automated and interactive file transfers
SSH keys work with two keys, private and public keys. The public key is stored on the SSH server and the private key is stored on the host where the SSH client is working.
Create an SSH Key
To create the SSH key, open the terminal and run the following command.
Enter the name and path for the keys, otherwise press Enter button for the default name and path. If you want to protect the ssh keys, then enter your desired password twice in the passphrase section. Otherwise, press Enter button to skip this step.
We have successfully generated the SSH keys. You can find these keys in the .ssh directory present under the Home directory of the user.
Now we need to add the public key to the GitHub for the command line access. To see the content of the public key, run the following command.
Copy and save the public key. The Public key will look like this.
- Log into the GitHub account, click on the Avatar and then click on the Settings option.
- Click on the SSH and GPG keys option present on the left side of the GitHub account.
- Click on the New SSH key option to add the Public SSH key to the GitHub.
- Paste the content of the SSH public key and then click on the Add SSH key button as mentioned below.
Test SSH Connection With GitHub
After adding the SSH key on GitHub, now we need to test the SSH connection with GitHub with the following command.
ssh -T [email protected]
You will get an output like this if everything is correctly configured.
Now you have successfully setup the SSH key on GitHub.
In today’s tutorial, we have discussed the need for SSH protocol and the SSH keys, the differences between private and public keys, and how we can generate and add them to the GitHub account. In the upcoming tutorials, we’ll share more about Git and GitHub.