1

I know that there are a ton of similar questions out there… but I couldn't find anything to help me with my problem. So… here we go.

I'm trying to push a repo to a selfhosted GitLab instance. I had to regenerate my SSH keys and for some reason this broke everything and I just can't figure out why. Whenever I try to push I get the following error:

Connection closed by [HOST] port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

I have the new public key added to GitLab and I have reconfigured my SSH config to also use the new key:

Host gitlab.[mydomain]
  User              git
  Hostname          gitlab.[mydomain]
  IdentityFile      ~/.ssh/private/[keyfile]
  IdentitiesOnly    yes

I've double and tripple checked everything. I am the owner of the Repo, the Repo still exists on the GitLab instance, the url in my .git/config is correct, I've added the correct public key to GitLab and the domain and filename in my ssh config are correct as well… and yet it doesn't work for some reason.

For testing purposes I've created a Repo on GitHub, added that as another remote. I can push to GitHub without any issues. I've even tried adding the same SSH key I use for GitLab to GitHub and editing my entry in the SSH config to match. Pushing still works fine.

I'm really confused at this point and I feel like I'm missing something blatantly obvious… but I just can't get it fixed.

1 Answers1

0

First, test if your key is accepted by GitLab:

ssh -Tv gitlab.[mydomain]

That should end with a Welcome message.

Then, make sure to use the right URL

git ls-remote gitlab.[mydomain]:aProject/aRepo

That will force SSH to consider your ~/.ssh/config file.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hey, thanks for the answer. Unfortunately GitLab doesn't accept the key at all… I've done a lot more of digging and apparently there is a bug with GitLab accepting new SSH keys: https://gitlab.com/gitlab-org/gitlab/-/issues/212178 I guess that's the source of the issue. No wonder that nothing seems to work if the issue is happening within GitLab somewhere. ,_, – Andreas Grafen May 13 '20 at 14:35
  • @AndreasGrafen Did you try with an classic PEM key format? (https://stackoverflow.com/a/53645530/6309) – VonC May 13 '20 at 15:16
  • I did but it doesn't seem to change anything. You can see the output of the connection attempt here: (https://pastebin.com/q9CAHQBm). Maybe this can help? When I'm comparing this to a working connection it seems like it's just randomly closing the connetion… – Andreas Grafen May 14 '20 at 11:26
  • @AndreasGrafen At this point, I would launch the SSH daemon in debug mode on the server side and check its log. (https://stackoverflow.com/a/41844152/6309) – VonC May 14 '20 at 12:53