Skip to content

How to set Git on Linux and connect to GitHub with SSH

Aleksandar Karastoyanov edited this page Apr 5, 2023 · 1 revision

This manual will give you the basics of how to set Git on Linux and use properly the SSH(Secure Shell) protocol to establish connection between your Linux OS and your GitHub profile.


💾 Download and install Git on Linux Debian.

Check if git is installed:

git --version

If you have git installed, you would see a similar output git version 2.30.2. If the package is missing you can download and install it in the bash(Debian):

sudo apt update $$ apt install git


⚙️ Before setting up the SSH connection, we need to configure git:

git config --global user.name "" - Place your display name in the quotes. This is the name which will appear after you commit code into GitHub

git config --global user.mail "" - Place your email address in the quotes. It is recommended to use the same Email address you used to make account in GitHub.

git config --global core.editor vim - Make vim default git editor to write and edit commit messages, commits and pull-requests title and description. If you prefer any other text editor, e.g. nano, you can change this config.

Finally, run git config -l to check your current global configuration. You should see a similar output:

image


🔐 Time to set SSH protocol and authorize Linux with our GitHub account

Run in Bash: ssh-keygen -t rsa -b 4096 -C ""

With initializing ssh-keygen we begin to create a SSH key pare which we will use to establish connection:

  • -t - we can set the specific algorithm which we will use to generate the SSH key, in our case rsa

  • -b - we specify the size of the key in bytes. By default the rsa algorithm is using 2048 bytes, but the max size can go up to 4096 bytes

  • -C "" - Place your GitHub account Email address in the quotes

Pressing Enter will execute the command and you will have to set few specific configurations:

  • Enter file in which to save the key (/home/alex/.ssh/id_rsa): - enter the directory where the SSH key to be saved/generated. By default, ssh-keygen will create a new directory.ssh in your home folder. For now we will stick with the default settings.

  • Enter the passphrase(empty for no passphrase): - set additional password which will be prompted when trying to commit new changes to repository. Can be set as blank password(no password).

  • Enter same passphrase again: - Repeat the same password

If everything went successfully, you will see a similar output.

image

Two new files has been generated in your ~/.ssh directory.

⚠️ id_rsa is containing your Private SSH key. Do not share this file and it's contents with anyone!

🌐 id_rsa.pub is your Public SSH key and it's totally fine to share it with anyone on the web.

image


:octocat: Upload the SSH key to GitHub

  • Copy the public SSH key from id_rsa.pub file. Copy the entire content of the file, do not leave anything behind.

  • Open GitHub.com and open your profile(top right corner)

  • Go to Settings - SSH and GPG keys

  • Click on New SSH key button

  • In the Title bar give the new SSH key a name by your choice.

  • Leave Key type as Authentication key

  • Paste the Public SSH key in the empty field Key

  • Finally press Add SSH key

image

Your are done! Now go back to Linux and execute in Bash the following command to check if your are successfully authorized with GitHub through SSH.

ssh -T [email protected]

If you get the following message, everything seems to be working:

image