How to Use SSH to Link with GitHub

If you are tired of constantly entering your credentials every time you need to make a pull, push or commit to GitHub; then there is a way to get around this and the best part is it’s super secure. we can use SSH protocol to perform all of the GitHub tasks you usually do but without entering your credentials every time. so, let’s see how we can do this. 

Prerequisites!

  • Must know what SSH protocol is (What is SSH)
  • Must be familiar with bash scripting commands
  • Must have git installed (Download git)

Initially, we will create our public and private keys and then to connect with GitHub account we need to copy our public key that we created on our local machine or laptops and copy it to GitHub account and that’s basically it. Let’s have a look how it’s actually done. 

STEP 1: Creating SSH Public and Private Keys

Open up gitBash(simply search it up in windows search bar) if you’re using Windows or a terminal if you’re using Mac OS or Linux distribution and type in the following command to generate the keys:  

				
					ssh-keygen –t rsa –b 4096
				
			
Generating SSH Key Pairs on Local Machine
Generating SSH Key Pairs on Local Machine

It’s going to ask you a few questions you just have to press enter all the way. Look at the above image, it will tell you if you’re doing everything correctly. Notice in the image above while creating the keys, it also tells you the location to where it is stored. In my computer it’s stored in C directory, it may differ for you.  

 

STEP 2: Adding SSH Public Key on GitHub

Afterwards, you have to go to that location and copy the content of the file named “id_rsa.pub”. Just open it up as a notepad file and copy the content. Once copied, then open your browser and login to your GitHub account. Follow the below steps afterwards: 

1. Go to GitHub account, click on profile picture on the top right and select settings option in the dropdown menu 

SSH to Link with GitHub - Settings Option to Add Keys
SSH to Link with GitHub - Settings Option to Add Keys

2. Select SSH and GPG keys option in the left panel 

SSH to Link with GitHub - Adding SSH Keys to GitHub
SSH to Link with GitHub - Adding SSH Keys to GitHub

3. Finally, you will be taken to a page where you can add your SSH keys as shown in the below picture just click on the new SSH key button. 

SSH to Link with GitHub - Adding New SSH Key
SSH to Link with GitHub - Adding New SSH Key

Lastly, you have to enter your public key that you had copied before an add a suitable title. the title can be anything just put something that you can remember where you had copied the public key from. after that just click add as such key button and you’re done. 

Now try cloning a new GitHub repository but this time choose the SSH link instead of the HTTP link like the picture shown below. After you’ve cloned it just use, you’ll get commands as you normally would, and you would notice that it will never ask you for your credentials for any command you execute.

SSH to Link with GitHub - SSH Link to Clone Repo
SSH to Link with GitHub - SSH Link to Clone Repo

And that’s a Wrap! 

Hope this article was informative to what you were looking for. And hopefully now you know how to use SSH to link with GitHub. Please like this article and leave down below. 

Have a great one!