Git Workflow: Connecting Through SSH

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 you must of have encountered a number of issues. One of such issues is GitHub asking for username and password for every commit you make, this slows down workflow and can be really frustrating.

The reason this happens is because a lot of users interact with online repositories over the terminal using HTTPs 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.

Lucid Blog 2.png

Thankfully there's a protocol know as the Secure Shell (SSH) that makes connecting and authenticating remote servers and services(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 login

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 actually have existing keys so as to avoid creating another one. 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 you take you to the location you want to save the key, accept the default location by pressing enter. The next process involves entering a secure passphrase which is more or less an added security layer that makes sure your credentials are safe.

Once that is done the next step is to add your key to the SSH agent but before that you have to ensure that the agent is running and to check you can use the following command.

eval $(ssh-agent -s)
  > Agent pid 400

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

$ ssh-add ~/.ssh/id_rsa

Having added your key to the SSH agent its time to add the said key to your GitHub account but it has to be first of all copied. Once the command is entered it should display your SSH key, copy it.

cat ~/.ssh/id_rsa.pub

After copying your 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 and GitHub should ask for your your password and voila 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

Lucid Blog 1.PNG