Using SSH Keys with Gitlab and Github

Tram Ho

In this article, I will guide you to create ssh keys for Gitlab and Github

What is SSH? Secure Socket Shell is a network protocol used to establish a secure network connection, using the ssh key:

  • Secure client connection to gitlab/github system
  • No need to enter github or gitlab password every time you pull or push code

Working mechanism:

  • You will have 2 keys: public key and private key, you will provide your public key to git server
  • Done ssh-agent will do all the rest for you. Each time you pull, push ssh-agent will automatically send the credentials.

Generate SSH Key Step 1: Check if you have any ssh key Open terminal and run Windows/Linux command

The above command will check if there is any ssh key in the .ssh directory

The public key will have a .pud extension (, the private key has no extension (id_rsa), if you already have an ssh key pair you can skip step 2 and move on to step 3.

Step 2: Generate a new SSH Key Run the following command on the terminal:

To be more concise you can use this command:

Step 3: Add your key to ssh-agent Make sure ssh-agent is enabled with the command:

Add your ssh key to the ssh-agent

Step 4: Add ssh public key to account on your server (gitlab, github ….)

  • For Gitlab Access the address: Select SSH Keys, the Title part is just a name, so you can name whatever you want, the key part enters the id_rsa file. pub


Then click the Add Key button and you’re done

For Github Go to: And do the same

Step 5: Check the connection

Ok now you can use the ssh link already.

Share the news now

Source : Viblo