27

I was trying to push changes to the branch but i got this error:

remote: Your SSH key has expired.
remote: 
remote: ========================================================================
remote: 
fatal: Could not read from remote repository.

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

i generated new access token in gitlab settings but i'm not sure how can i add to my project so i can push again

3
  • 3
    Why did you generate a new access token when you need a new ssh key? Commented Aug 31, 2022 at 15:24
  • 4
    Access tokens and SSH keys are two separate access mechanisms: the former is used for HTTP access, the latter for SSH access. Commented Aug 31, 2022 at 15:24
  • I have same issue here, solve just read from this article lucaberton.medium.com/… Commented Oct 28 at 2:44

7 Answers 7

38

This is a hack but if you're using that ssh key elsewhere to and don't want to update it everywhere AND you don't have security concerns, you can scroll all the way down on the page where gitlab displays your expired ssh key and hit Remove. Then you can add the same key again and have 1 more year validity on it

Sign up to request clarification or add additional context in comments.

4 Comments

It does not allow me re-add the key even after deleting it. "Fingerprint sha256 has already been taken"
you may have done REVOKE instead of delete.
Worked for me. Tried after refresh ?
This worked for me as well. Just copy the key, delete it, and then re-add the same key.
19

The SSH-key is not your access-key.

Go to settings and setup a new SSH-key.

Edit

  1. Click on "Preferences"
    Image for opening settings dialoge
  2. Click on "SSH Keys" (it is under "Access token")
    Image of settings
  3. Just add a key (fill out "Key" and "Title" and press "Add key" button
    SSH Dialog

4 Comments

sorry, but where can i find an option to setup a new ssh-key. I only could find the option to generate the access tokens
is there a way to make public key private ?
A public key private? What do you mean?
17

You need to go to Profile->SSH Keys , remove the key that expired and then re-add it.

Although not recommended, you can avoid that a SSH Key expires by removing the expire date on creation. By default, expire date is set to next year. If you click the cancel icon, expiration date is set to never: enter image description here

1 Comment

That is true. Weird the Gitlab team did not realize it's sort of an anti-security feature to not provide (a button for )changing the expiration date once the key was added. That motivates to rather unset the expiration.
9

Follow the documentation to generate a new SSH key and remove your old one / add the new one:

https://docs.gitlab.com/ee/user/ssh.html

Comments

4

In case anyone else lands on this question looking for clues on why their new key does not work after configuring your SSH client to use it:

For me, I had to remove the expired key from GitLab (and potentially your client) to make it proceed with trying the new one.

1 Comment

Same for me,I had 3 old keys and Git just would not use the new one till I removed the old ones in GitLab->SSH Keys
2

Removing the old SSH key is important. I got rid of the error once I deleted the old key.

Comments

0

For anyone who manages multiple ssh keys on your local computer, make sure you do not have the catch-all host first in your config file.

Move this line below all other hosts

Host *
IdentityFile ~/.ssh/your-private-key

ssh will use the first host that matches and this can conflict with your actual host and its key file. Or better still do not use the catch-all host and specify each host seperately.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.