Hoppa till innehåll

SSH-keys troubleshooting

Before anything else, if it ain't broken, don't try to fix it!

Try:

ssh -T git@gitlab.lnu.se

If the result is successful:

Welcome to Gitlab, @xx222yy!

Everything is working and you can go on to working with git and gitlab.

LNU Guest

You will not be able to use SSH over the campus network named "LNU Guest". Please switch to "Eduroam".

Commands great for troubleshooting

$ ssh-add -l

List all active SSH-keys

$ ssh-agent

Check if the ssh-agent is running

$ ls ~/.ssh/

List the content of the folder where your SSH-keys are stored.

$ ssh-add ~/.ssh/gitlab_rsa

Add a SSH-key to the SSH-agent.

Permission denied on gitlab

The following error might occurr:

$ git clone git@gitlab.lnu.se:1dv000/student/ln222xy/exercise/hello-world.gi
Cloning into \'hello world\'...
git@gitlab.lnu.se: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists

This error can be caused by several things, but the most common are:

  1. The SSH-key on your computer does not match the one you added to gitlab
  2. The SSH-agent that handles the keys on your computer is not started
  3. The SSH-key on your computer is not added to your SSH-agent

1 - The SSH-keys does not match

Start by opening a Git Bash shell and write:

$ ssh-add -l

If the output is something like:

4096 SHA256:IzCrvVdKDLmpdOHkg1KzL1iIcKVljWGhEhl9M1jPw/E ln222xy@student.lnu.se (RSA)

Then your ssh-agent is running and your SSH-key is added to the agent. If you get another output, see 2 and 3.

Make sure your fingerprint above matches the one on Gitlab by visiting https://gitlab.lnu.se/profile/keys and clicking on your SSH-key. Compare the output at "Fingerprints SHA256" with the output produced when you did ssh-add -l. If they match, all should be good.

If they do not, you need to add the ssh-key to your GitLab account.

2. SSH-agent not started (Common problem)

Start by opening a Git Bash shell and write:

$ ssh-add -l

If the output is something like:

Could not open a connection to your authentication agent.

then your ssh-agent is not running.

On Windows, if issuing the command ssh-agent does not give you a "pid" number but rather a number of text lines, you can try to run the ssh-agent by typing the following:

eval $(ssh-agent -s)

It should now return something like Agent pid 59566

3. No SSH-keys loaded into agent. (Common problem)

Start by opening a Git Bash shell and write:

$ ssh-add -l

If the output is something like:

The agent has not identities.

then your SSH-keys are not added to the SSH-agent.

To add a SSH-key to the agent run the command:

$ ssh-add ~/.ssh/theNameOfYourSSHKey

You can find the name of your keys by running:

$ ls ~/.ssh/

Maybee your key is called gitlab_rsa and if so the command to run will be:

$ ssh-add ~/.ssh/gitlab_rsa

The problem with this aproach is that you will need to run this command on every reboot/login of your computer. You can solve this by editing the file named config in the folder ~/.ssh/

Edit the file using VS Code or another editor and add the following line at the end:

IdentityFile ~/.ssh/gitlab_rsa

(Where gitlab_rsa is the name of your key)

CCBY