【问题标题】:Can't connect to GitLab via ssh无法通过 ssh 连接到 GitLab
【发布时间】:2020-05-12 08:27:24
【问题描述】:

首先,我使用以下命令创建了 ssh 密钥对:

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

然后,我将 id_rsa.pub 文件的内容添加到我的 GitLab 配置文件中。 但是当我尝试测试我的 SSH 密钥是否被正确添加时:

ssh -vvvT user@some.gitlab.com

输入正确密码后,我得到以下日志:

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

没有别的了。日志打印已停止,控制台现在已冻结。 我还尝试使用命令从我的 GitLab 克隆一些项目:

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

但我遇到了错误:

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

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

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 如果您将遥控器更改为使用git@ 而不是user@ 是否有效?
  • 不,它不起作用。我两种都试过了: 1. 'git clone ssh://user@...' 和 'ssh -vvvT user@some.gitlab.com' 来测试; 2. 'git clone ssh://git@...' 和 'ssh -vvvT git@some.gitlab.com' 进行测试

标签: git ssh gitlab


【解决方案1】:
shell request accepted on channel 0

这意味着 ssh 部分可能正在工作。

用于克隆 repo 的 URL 将不起作用:

  • 用户需要是 git(总是在典型的 GitLab 安装中)
  • URL 需要包含用户/组和 repo

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

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

如发现 by the OP in the chat问题在于使用的 SSH 库

问题出在 OpenSSH 客户端。
在讨论期间,我使用的是适用于 Windows 的 OpenSSH 客户端。
改成 Git Bash 之后就开始工作了!

mentioned here 认为 Windows 10 (1809+) 添加了 OpenSSH Client(和服务器)。
但是Git for Windows 带有OpenSSH 8.1

由于 Windows SSH 是 openSSH 的一个分支 (PowerShell/openssh-portable),因此使用来自 Git 的 SSH 更安全。

更一般地,使用带有路径开始的Git:

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

这将确保您首先使用 Git 及其运行时依赖项(然后是 Windows)。

【讨论】:

  • 感谢您的回答,但它对我不起作用。同样的结果
  • @IlyaBerdzenishvili 好的,我已经相应地重写了答案。
  • 关于 'ssh://git@some-gitlab-url/some-group/some-project.git' 格式。是的,我正在使用这种格式,没有组的 'ssh://user@some-gitlab-url/some-project.git' 只是为了简化。
  • 关于“用户需要是 git(总是在典型的 GitLab 安装中)”。请参阅我在问题下方的评论:'我都尝试过:1. 'git clone ssh://user@...' 和'ssh -vvvT user@some.gitlab.com' 进行测试; 2. 'git clone ssh://git@...' 和 'ssh -vvvT git@some.gitlab.com' 来测试'
  • @IlyaBerdzenishvili 它是私人回购吗?您的用户(您在其中注册了公共 SSH 密钥)是否有权通过 Web GUI 访问它?
猜你喜欢
  • 2021-08-28
  • 1970-01-01
  • 2021-04-07
  • 2020-07-27
  • 2015-10-21
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
相关资源
最近更新 更多