Git Workflow: Connecting Through SSH
categories tags date share

Joel Onwuanaku 3 Minutes Read

Git Workflow: Connecting Through SSH


So if you're like me, chances are you've tried to set up a repository on GitHub once or twice and encountered a number of issues. One such issue is GitHub asking for a username and password for every commit you make. This slows down the workflow and can be really frustrating.

The reason this happens is that a lot of users interact with online repositories over the terminal using HTTP URLs, which in itself is an awesome standard because it's straightforward and just works, However like every other thing there's always a "but," and in this case, it involves GitHub requesting for your login details for every push or pull request which can become frustrating over time.

Thankfully, there's a protocol known as the Secure Shell (SSH) that makes connecting to and authenticating with remote servers and services (including GitHub) a breeze. With SSH Keys, connecting to services like GitHub is easy, as you don't have to supply your credentials every time there is a need to log in

In this article, I will be showing you how to connect to GitHub using SSH Keys. The very first thing is to check whether you already have keys to avoid creating another set. Using your favourite terminal, enter the following command to check if you have existing keys.

ls -al ~/.ssh

And if you don't have any existing keys, you can create one using this command.

ssh-keygen -t rsa -b 4096 -C "youremail@example.com"

This should take you to the location where you want to save the key, or you can accept the default location by pressing enter. The next step involves entering a secure passphrase, which serves as an added security layer to help keep your credentials safe.

Once that is done, the next step is to add your key to the SSH agent. Before that, you have to ensure the agent is running; to check, run the following command.

eval $(ssh-agent -s)

Now that you've got the SSH agent running, the next thing is to add your key to the SSH agent. This is done by

ssh-add ~/.ssh/id_rsa

Having added your key to the SSH agent, it's time to add it to your GitHub account, but you'll need to copy it first. Once the command is entered, it should display your SSH key, and copy it.

cat ~/.ssh/id_rsa.pub  

After copying your SSH Key, head to GitHub > Settings > SSH and GPG Keys. Click on Create A New SSH Key, add a title, say perhaps the name of the device you're using that particular key with, e.g., "Acer Swift 3," in the field assigned "Title," and paste your key in the field designated "Key". Hit Add SSH Key. GitHub should prompt for your password, and voilà, you're good to go.

Once you're done, try pushing a new project to your GitHub; you should be able to make pull and push requests without GitHub asking for your password.

 

Comments

No comments yet. Be the first to share your thoughts.

Leave a comment