4

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

ssh-keygen -o -t rsa -b 4096 -C "email@example.com"

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 user@some.gitlab.com

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 no-more-sessions@openssh.com
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug3: receive packet: type 80
debug1: client_input_global_request: rtype hostkeys-00@openssh.com 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?

  • Does it work if you change your remote to use `git@` instead of `user@`? – bk2204 Jan 26 '20 at 23:22
  • No, it doesn't work. I've tried both: 1. 'git clone ssh://user@...' with 'ssh -vvvT user@some.gitlab.com' to test; 2. 'git clone ssh://git@...' with 'ssh -vvvT git@some.gitlab.com' to test – Ilya Berdzenishvili Jan 27 '20 at 04:47

2 Answers2

2
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).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for your answer, but it doesn't work for me. The same result – Ilya Berdzenishvili Jan 27 '20 at 06:45
  • @IlyaBerdzenishvili OK, I have rewritten the answer accordingly. – VonC Jan 27 '20 at 06:50
  • Regarding the 'ssh://git@some-gitlab-url/some-group/some-project.git' format. Yes, i'm using this format, the 'ssh://user@some-gitlab-url/some-project.git' without group was used just to simplify. – Ilya Berdzenishvili Jan 27 '20 at 06:58
  • Regarging the 'the users needs to be git (always in a typical GitLab installation)'. See my comment below the question: ' I've tried both: 1. 'git clone ssh://user@...' with 'ssh -vvvT user@some.gitlab.com' to test; 2. 'git clone ssh://git@...' with 'ssh -vvvT git@some.gitlab.com' to test' – Ilya Berdzenishvili Jan 27 '20 at 06:59
  • @IlyaBerdzenishvili Is it a private repo? Does your user (where you did register the public SSH key) has the right to access it through the Web GUI? – VonC Jan 27 '20 at 06:59
  • yes, it's corporative repo and i have access through Web GUI – Ilya Berdzenishvili Jan 27 '20 at 07:00
  • @IlyaBerdzenishvili The point (regarding `git@`) is that it does not make sense to use your login `user@` in an SSH URL: SSH does the authentication for you, under the service account `git` (which runs the GitLab instance) – VonC Jan 27 '20 at 07:00
  • @IlyaBerdzenishvili "And nothing else. Printing of log has stopped, and console is frozen now": that part is not OK: a GitLab instance should answer (https://docs.gitlab.com/ee/ssh/#testing-that-everything-is-set-up-correctly): "Welcome to GitLab, @username!" – VonC Jan 27 '20 at 07:03
  • @IlyaBerdzenishvili Can you try with `ssh -vvvT git@some.gitlab.com`? Again, "user" is never involved in a server for SSH connection. – VonC Jan 27 '20 at 07:05
  • Correct, this welcoming message is exactly what i'm expecting for – Ilya Berdzenishvili Jan 27 '20 at 07:05
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/206685/discussion-between-vonc-and-ilya-berdzenishvili). – VonC Jan 27 '20 at 07:05
  • @IlyaBerdzenishvili I have updated the answer with your conclusion, and some documentation. – VonC Jan 27 '20 at 13:55
0

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)

J.R. Bob Dobbs
  • 237
  • 3
  • 10