简体   繁体   English

无法通过 ssh 连接到 GitLab

[英]Can't connect to GitLab via ssh

Firstly, i created the ssh key pair with the command:首先,我使用以下命令创建了 ssh 密钥对:

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.然后,我将 id_rsa.pub 文件的内容添加到我的 GitLab 配置文件中。 But when i tried to test whether my SSH key was added correctly:但是当我尝试测试我的 SSH 密钥是否正确添加时:

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:我还尝试使用以下命令从我的 GitLab 克隆一些项目:

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?任何人都可以请帮我解决这个问题吗?

shell request accepted on channel 0

That means possibly the ssh part is working.这意味着 ssh 部分可能正在工作。

What would not be working would be the URL used to cloned the repo:用于克隆 repo 的 URL 将不起作用:

  • the users needs to be git (always in a typical GitLab installation)用户需要是 git(总是在典型的 GitLab 安装中)
  • the URL needs to include the user/group and the repo URL 需要包含用户/组和 repo

So not ssh://user@some-gitlab-url/some-project.git but所以不是 ssh://user@some-gitlab-url/some-project.git 而是

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 . OP 在聊天中发现,问题是使用的 SSH 库

The problem was with OpenSSH client.问题出在 OpenSSH 客户端上。
During the discussion I was using OpenSSH client for Windows.在讨论期间,我使用的是 Windows 的 OpenSSH 客户端。
After it was changed to Git Bash it has started to work!更改为 Git Bash 后,它开始工作了!

I mentioned here that Windows 10 (1809+) adds an OpenSSH Client (and server).在这里提到 Windows 10 (1809+) 添加了一个OpenSSH 客户端(和服务器)。
But Git for Windows comes with OpenSSH 8.1 .但是Windows 版 Git附带了OpenSSH 8.1

Since The Windows SSH is a fork ( PowerShell/openssh-portable ) of the openSSH one, using the one from Git is safer.由于 Windows SSH 是 openSSH 的一个分支( PowerShell/openssh-portable ),因此使用 Git 中的一个更安全。

More generally, using Git with a path starting with:更一般地,使用带有以下开头的路径的 Git:

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).这将确保您首先使用 Git 及其运行时依赖项(然后是 Windows)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM