Setting up Github on Linux

- 5 mins


Where is this article is going

I am using GitHub for each of my ongoing projects for a long time. Still, every week I discover techniques and the way it could be used to simplify the workflow and I amazed by the thinking behind it. This article is not about what Git is or how it is different from an existing version control system. There’s a ton of video and articles out there describing (or actually fighting, but obviously the winner is Github :) ) about difference systems comparison. Although I would suggest a video by Git creator Linus Torvalds speech on a visit to Google.

Basic configuration

If you don’t have an account yet please register one from here and continue to the following steps.

Open your terminal and use following commands to configure globally on your machine.

git config --global color.ui true

Replace ‘USERNAME’ with your git username

git config --global "USERNAME"

Replace ‘USER@EMAIL.COM’ with your git email

git config --global "USER@EMAIL.COM"

Setting up the ssh

You can use Git repository over a https connection. But if you rely on it heavily you sure will wish to have ssh connection between your pc and git repo. Mainly this will save a lot of time by skipping writing your username and password every time you want to do an operation.

To generate an ssh key first go to your home directory

cd ~

Type following command and replace “EMAIL_ADDRESS” with your github email (keep the quotation)

ssh-keygen -t rsa -b 4096 -C "EMAIL_ADDRESS"

If you don’t have a ssh key folder this command will create one

Generating public/private rsa key pair.
Enter file in which to save the key (/home/{USER_NAME}/.ssh/id_rsa): 
Created directory '/home/{USER_NAME}/.ssh'.

After that, it will ask for a passphrase along with a confirmation. If you want to learn more about passphrase read this. You should not leave it empty. Remember it or copy it somewhere else. You will need it few minutes later.

Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

If everything is going ok then you will get the following message with a key fingerprint and randomart image.

Your identification has been saved in /home/{USER_NAME}/.ssh/id_rsa.
Your public key has been saved in /home/{USER_NAME}/.ssh/
The key fingerprint is:
The key's randomart image is:

Now you need to add SSH key to the ssh-agent. Start ssh-agent by this command

eval "$(ssh-agent -s)"

This will show an output like this

Agent pid {PID_NUMBER}

Now add your ssh private key to the ssh-agent. If you created a key with a different name replace id_rsa with your name. After pressing enter a prompt will be open to give your passphrase. If you give it correctly a meesage Identity added: will be appeared.

ssh-add ~/.ssh/id_rsa

You can check your public key fingerprint by running this command

ssh-add -l

This should return a long list. If not you probably forgot a step or made a mistake. You can also check if the key is working by trying to connect to

ssh -vT

This will give you a list of possible ssh files and -1 or 0 message beside it. 0 means available and -1 means not available.

On your machine, go to ssh directory and output your key by this

cat ~/.ssh/ 

This will show the key. Copy it.

Now go to github settings page and use “New SSH key” button to add the key. On prompt give it a name that you can identify for which ssh is for which machine. And then add key and save it.

ssh -vT

This will give you a list of possible ssh files and -1 or 0 messages beside it. 0 means available and -1 means not available.

You might have to close the terminal and reopen to take the effect. Most of the time it isn’t a required step. But it is safe to do once.

After that, if you clone a directory always use ssh version link to do that. If you have an existing repository on your local than to use ssh you have to update the origin address.

Go to the main repo directory of your project on GitHub, under clone or download section open ssh section and copy the link.

On your machine, go to the repo directory and set origin url by this

git remote set-url origin COPIED_SSH_LINK

It’s all done. You can now access and use repository from your machine without explicit authentication.

Useful resources

Some of the resources I hope would be useful

comments powered by Disqus
rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora