【问题标题】:Gitlab: unable to connect with SSH key or HTTPSGitlab:无法使用 SSH 密钥或 HTTPS 连接
【发布时间】:2020-01-14 20:59:59
【问题描述】:

我正在做一个项目,需要将 Gitlab 项目克隆到我的计算机上。我在虚拟机中运行 CentOS 6。我无权访问 Gitlab 服务器或其信息,因为它属于第三方。

SSH 问题

我尝试了多种创建 ssh 密钥的方法,包括但不限于:

ssh-keygen -t rsa -C "Gitlab" -b 4096
ssh-keygen -t rsa -C "GitLab" -b 2048
ssh-keygen

我从来没有设置过密码。我以适当的方式将/home/jchambers/.ssh/id_rsa.pub 复制到Gitlab,但这是我的结果:

$ git clone git@localhost:Project/Project_stuff.git
Initialized empty Git repository in /home/jchambers/Project/Project_stuff/.git/
git@localhost's password: 
Permission denied, please try again.

我从未设置密码,我的 Gitlab 密码和我的计算机登录密码都不是这里期望的密码。根据this question,我跑了ssh -vT git@localhost

$ ssh -vT git@localhost
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /home/jchambers/.ssh/identity type -1
debug1: identity file /home/jchambers/.ssh/identity-cert type -1
debug1: identity file /home/jchambers/.ssh/id_rsa type 1
debug1: identity file /home/jchambers/.ssh/id_rsa-cert type -1
debug1: identity file /home/jchambers/.ssh/id_dsa type -1
debug1: identity file /home/jchambers/.ssh/id_dsa-cert type -1
debug1: identity file /home/jchambers/.ssh/id_ecdsa type -1
debug1: identity file /home/jchambers/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'localhost' is known and matches the RSA host key.
debug1: Found key in /home/jchambers/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_502' not found

debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_502' not found

debug1: Unspecified GSS failure.  Minor code may provide more information


debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_502' not found

debug1: Next authentication method: publickey
debug1: Offering public key: /home/jchambers/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/jchambers/.ssh/identity
debug1: Trying private key: /home/jchambers/.ssh/id_dsa
debug1: Trying private key: /home/jchambers/.ssh/id_ecdsa
debug1: Next authentication method: password
git@localhost's password: 

并更新了这些权限:

chmod 700 /home/git/.ssh
chmod 600 /home/git/.ssh/authorized_keys

我不明白公钥身份验证部分有什么问题。

编辑*

根据我收到的答案,我更改了命令中的主机名,使其成为:

$ git clone jessica.chambers@my-gitlab.gitlab-platform.net:Project/Project_stuff.git
Initialized empty Git repository in /home/jchambers/Project/Project_stuff/.git/
ssh: connect to host my-gitlab.gitlab-platform.net port 22: Connection timed out
fatal: The remote end hung up unexpectedly

我也再次运行了这个,但连接似乎总是超时:

$ ssh -vT jessica.chambers@my-gitlab.gitlab-platform.net
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to my-gitlab.gitlab-platform.net [12.34.567.89] port 22.
debug1: connect to address 12.34.567.89 port 22: Connection timed out
ssh: connect to host my-gitlab.gitlab-platform.net port 22: Connection timed out

HTTPS 问题

由于 SSH 的情况似乎没有结果,我尝试了 HTTPS 方法。它最初没有工作,所以根据另一个问题,我做了以下更改:

sudo yum install ca-certificates
update-ca-trust force-enable

这没什么区别。这是我尝试通过 HTTPS 克隆时得到的结果:

$ git clone https://my-gitlab.gitlab-platform.net/gitlab/Project/Project_stuff.git
Initialized empty Git repository in /home/jchambers/Project/Project_stuff/.git/
error:  while accessing https://my-gitlab.gitlab-platform.net/gitlab/Project/Project_stuff.git/info/refs

fatal: HTTP request failed

我的互联网连接,虽然在代理之后,但可以正常工作(例如,我可以通过yum 安装,并使用网络浏览器)。 Gitlab 项目确实需要登录,所以也许我需要在某处输入?

如果有人可以为我指出 SSH 问题或 HTTPS 问题的正确方向,那将非常有帮助。

【问题讨论】:

    标签: git ssh https gitlab


    【解决方案1】:

    我相信你的 GitLab 的 SSH 端口不是 22。在你使用 SSH 的 URL 中,你默认使用端口 22,我猜测是你的服务器的 SSH 守护进程在回答,而不是 GitLab - 因此你的公钥没有不工作。 HTTPS 也一样,我假设默认端口不是 443。

    如果您可以分享有关 GitLab 如何安装和运行的更多详细信息 - 可以为您提供更多指导。

    【讨论】:

    • 我无法访问它的运行方式(由另一家公司运行),但我会尝试更改端口 :)
    • 如何访问 gitlab 的 Web UI URL?
    • 哦,等一下。如果它由另一家公司运行,那么您的 SSH URL 通常不正确,因为您正在尝试连接到 localhost。这意味着您希望 git 在您执行命令时在同一台机器上运行。要从远程计算机克隆,您将拥有一个类似 git@hostname_of_gitlab:Project/Project_stuff.git 的 URL
    • 好的,所以我再次尝试使用 ssh 调整主机名,我可以确认它通过端口 22 但它仍然无法正常工作,我将用插图编辑我的问题
    • 一般情况下,如果你可以访问 GitLab 的 UI,在它的“克隆”按钮中可以使用一个 URL。调试这样的问题是相当不可能的。您提到您使用代理,为了使 https 克隆正常工作,您需要在使用 git 命令(如 export https_proxy="address_of_your_proxy:port")之前导出 https_proxy 环境变量。
    猜你喜欢
    • 2016-11-10
    • 2021-01-15
    • 2022-07-11
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    相关资源
    最近更新 更多