Adding a Public Key to GitLab Settings

Here’s how to tell GitLab about your workstation by giving it your public key.

But First …

Step by Step

Go to the https://gitlab.com web site and login (depending on how you signed up).

Click on your icon in the top right.

Select Settings and click on it.

💬 At this point you might want to make your window bigger so you can see the writing in the left sidebar.

Find the SSH Keys near the bottom left in the sidebar.

Notice the big empty text field.

You are ready to paste in your public key, but now we have to go get it from your terminal.

Return to your terminal command line.

We will use the cat command to dump out the content of your public key, which lives in ~/.ssh/id_rsa.pub by default.

cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSLgcGIz6b88L6PMRRjEXnUpopCeLxE3C8+gHGvAQbiZER0OT3q5HnRa7vkZf4HiP0v0OvVO+V73ogeBTc9Q7/wy578wO1sXVzkW6782pqwGCibjopFOBxN1jGa2o6He1S7t+DvRZGXsiHJ8moRTUsX1DHMJZN4bflmAF2oL29/78dezVN8mf4rfGdz3HiaWLnETR1Xn9LY+CRQpvYyP8tYunmPsxSdibX3v5o9CBx2hL4inElhnEUia308jQ1S5Vh5+cKsTK1Md0H4UPX7nmz9Fn1ff+ETzm0FcBWzj1RqA3wThbkqqPY5NsD/TnpZT2+4On70mSqZn0CSn1z0aOD rwx@sk

Select that output with your mouse and copy it.

⚠️ Be sure to get the ssh-rsa and the rwx@sk at the end. These are part of the key itself and must be included. People frequently forget to include these when they copy.

With the public key in your paste buffer now return to the web page.

Paste into the text field.

Now you should see the name and other field update as well.

Click on the green Add Key button.

Your public key is now updated.

Let’s test it from the terminal. Return to the terminal command line.

I call this a “git ping” since it is a way to check that GitLab or GitHub know about you.

Even though ssh is disabled on these services, attempting to remotely connect to them with ssh from the command line shows us if everything is working as expected.

ssh git@gitlab.com

⚠️ Don’t use your username, use git@gitlab.com.

If you see something like the following warning just say yes. It is protecting you from future man in the middle attacks.

The authenticity of host 'gitlab.com (35.231.145.151)' can't be established.
ECDSA key fingerprint is SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw.
Are you sure you want to continue connecting

After you say yes you should see something like the following:

Warning: Permanently added 'gitlab.com,35.231.145.151' (ECDSA) to the list of known hosts.

Then, if everything is working you should see a friendly greeting from the service.

PTY allocation request failed on channel 0
Welcome to GitLab, @robmuh!
Connection to gitlab.com closed.

At this point you should probably continue setting up GitLab on your workstation and clone your first project if you have not yet done so.