Skip to main content
Gå til innhold

SSH Access

Before you can push code to our GitLab installation using the Git client, you will need to set up SSH access to our GitLab instance.

Creating a SSH key

First check if you already have a SSH key by running cat ~/.ssh/id_rsa.pub. If you have a key available, you should see it in the terminal, and you can skip to the Add SSH key to GitLab-section. If not, you will receive an error similar to:

$ cat ~/.ssh/id_rsa.pub
cat: /home/username/.ssh/id_rsa.pub: No such file or directory

In that case you will need to create a new SSH key. To do that, run ssh-keygen -t rsa.

This command will ask where you want to store the key. Accept the default location by pressing the enter-key on your keyboard. It will also ask you to set a passphrase for the key. Enter a passphrase to keep your SSH key secure.

The full command output will be something like:

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Created directory '/home/username/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:j2bJpHGFXO1AsifvAT/IY0rs3FIz5/Spp1TVEx2tkjA username@14cb7032b413
The key's randomart image is:
+---[RSA 2048]----+
| ..o. o+|
| . =E . .+|
| * o= ..o.|
| . . O +.. .|
| + S B .. |
| + @ % = . |
| * B = o |
| + . .. |
| oo |
+----[SHA256]-----+

Add SSH key to GitLab

With the SSH key available you should be able to run cat ~/.ssh/id_rsa.pub and get the SSH key:

$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC[...] username@somehost

This is the key you will need to add to GitLab. Access your SSH key settings in GitLab at gitlab.sikt.no/-/profile/keys.

There you should have a text field where you can add the SSH key. Copy the entire line from the cat ~/.ssh/id_rsa.pub-command (everything starting with ssh-rsa up to and including the username@somehost-part). Then paste it into the text field and click the "Add key" button.

Verifying GitLab access

When you have added the key to GitLab, you can verify that you have access by running ssh git@gitlab.sikt.no.

The first time you run this command, you will be asked to accept the public key of the server. Enter yes and press enter to continue connecting.

You will also need to provie the passphrase you used when generating the key.

Once you have connected, you should receive a line from GitLab:

Welcome to GitLab, @username!

The full command output should look like:

$ ssh git@gitlab.sikt.no
The authenticity of host 'gitlab.sikt.no (13.49.120.178)' can't be established.
ECDSA key fingerprint is SHA256:Gbr59WYi4mMIN/PQnLsaRPLbO35HfwI3w/FYA//fzbU.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitlab.sikt.no,13.49.120.178' (ECDSA) to the list of known hosts.
Enter passphrase for key '/home/username/.ssh/id_rsa':
PTY allocation request failed on channel 0
Welcome to GitLab, @olav.morken!
Connection to gitlab.sikt.no closed.