Ilya Berdzenishvili
Ilya Berdzenishvili

Reputation: 261

Can't connect to GitLab via ssh

Firstly, i created the ssh key pair with the command:

ssh-keygen -o -t rsa -b 4096 -C "[email protected]"

Then, i added content of the id_rsa.pub file to my GitLab profile. But when i tried to test whether my SSH key was added correctly:

ssh -vvvT [email protected]

i've got the following log after correct password was typed:

debug3: send packet: type 61
debug3: receive packet: type 60
debug2: input_userauth_info_req
debug2: input_userauth_info_req: num_prompts 0
debug3: send packet: type 61
debug3: receive packet: type 52
debug1: Authentication succeeded (keyboard-interactive).
Authenticated to some.gitlab.com ([xxx.xxx.xxx.xxx]:xx).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Requesting [email protected]
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug3: receive packet: type 80
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug3: receive packet: type 91
debug2: channel_input_open_confirmation: channel 0: callback start
debug2: fd 3 setting TCP_NODELAY
debug2: client_session2_setup: id 0
debug2: channel 0: request shell confirm 1
debug3: send packet: type 98
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
Last failed login: Sun Jan 26 21:33:13 UTC 2020 from some-freeipa.com on ssh:notty

And nothing else. Printing of log has stopped, and console is frozen now. Also i've tried to clone some projects from my GitLab with command:

git clone ssh://user@some-gitlab-url/some-project.git

But i've got the error:

Permission denied (publickey).
fatal: Could not read from remote repository.

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

Could anyone, please, help me with the issue?

Upvotes: 6

Views: 14354

Answers (3)

Jonatan Öström
Jonatan Öström

Reputation: 2609

I had the same (or very similar) issue on Ubuntu 22.04, with the error message

The authenticity of host 'gitlab.com (172.65.251.78)' can't be established.
ED25519 key fingerprint is SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? 
Host key verification failed.
fatal: Could not read from remote repository.

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

The solution was to update ~/.ssh/config with

Host *gitlab*
    IdentityFile ~/.ssh/id_rsa
    IdentitiesOnly yes
    StrictHostKeyChecking no

Where the last line made the difference. Also note that if using RSA keys they must be at least 2048 and maximum 8192 bits. So for example ssh-keygen -t rsa -b 4096 creates a valid key pair id_rsa, id_rsa.pub.

Hm, reading what I just posted, I think maybe I just didn't write yes when prompted (see the error message above)... Maybe that used to be the default and now it says [fingerprint] as the default... Anyway maybe someone equally confused will be helped by this :D

Upvotes: 1

J.R. Bob Dobbs
J.R. Bob Dobbs

Reputation: 295

Adding my answer, since I just spent about 4 hours resolving the issue for Permission denied (publickey).

I had to update the .ssh/config file with the following:

# Gitlab | example
Host <gitlabUserName>.gitlab.com
  Host gitlab.com
  Preferredauthentications publickey
  IdentityFile ~/.ssh/<ssh_key_type>

You'll need to add your own gitlab user name for the Host on the second line

you'll need to add the ssh_key_type (rsa, id_ed25519, etc)

Upvotes: 1

VonC
VonC

Reputation: 1323613

shell request accepted on channel 0

That means possibly the ssh part is working.

What would not be working would be the URL used to cloned the repo:

  • the users needs to be git (always in a typical GitLab installation)
  • the URL needs to include the user/group and the repo

So not ssh://user@some-gitlab-url/some-project.git but

ssh://git@some-gitlab-url/some-group/some-project.git

As found by the OP in the chat, the issue was the SSH library used.

The problem was with OpenSSH client.
During the discussion I was using OpenSSH client for Windows.
After it was changed to Git Bash it has started to work!

I mentioned here that Windows 10 (1809+) adds an OpenSSH Client (and server).
But Git for Windows comes with OpenSSH 8.1.

Since The Windows SSH is a fork (PowerShell/openssh-portable) of the openSSH one, using the one from Git is safer.

More generally, using Git with a path starting with:

set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\cmd;%GH%\mingw64\bin;%PATH%

That will ensure you are using Git with its runtime dependencies first (and then Windows).

Upvotes: 4

Related Questions