【问题标题】:gitlab.com SSH connection timed outgitlab.com SSH 连接超时
【发布时间】:2021-03-09 06:44:41
【问题描述】:

我尝试让 Gitlab 与 SSH 一起工作,但它不会。

我已经完成了以下步骤:

1) 生成 ssh-key

ssh-keygen -t rsa -C "myemail@myhoster.com" -b 4096

2 ) 在文件夹 /Users/myUserName/.ssh/ 中将键命名为“id_rsa”

3) 通过复制密钥

pbcopy < ~/.ssh/id_rsa.pub

4) 将密钥插入 gitlab

当我现在尝试克隆存储库时,我收到以下错误:

$ git clone git@gitlab.com:myName/repositoryName/ repoName
Cloning into 'repoName'...
ssh: connect to host gitlab.com port 22: Operation timed out
fatal: Could not read from remote repository.

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

出了什么问题?

【问题讨论】:

  • 尝试使用您自己的用户名git clone myUsername@gitlab.com:myName/repositoryName/ repoName

标签: ssh timeout repository gitlab


【解决方案1】:

我发现自己也遇到了同样的问题。

正如 Adrian Dymorz 所述,您可以使用以下命令检查您是否可以通过 SSH 访问 Gitlab:

ssh git@gitlab.com

您应该会收到这样的回复:

...
Welcome to GitLab, <Gitlab ID Account>!
Shared connection to altssh.gitlab.com closed.

如果没有,那么 betarrabara 应该可以解决您的问题但是您不应该提供您的 id_rsa 而是您的 id_rsa.pub强> 代替:

Host gitlab.com
Hostname altssh.gitlab.com
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa.pub

【讨论】:

  • 它仍然抛出bash ue@DESKTOP-EVCRRVA /cygdrive/c/Users/ue/.ssh $ ssh git@gitlab.com The authenticity of host '[altssh.gitlab.com]:443 ([172.65.251.182]:443)' can't be established. ECDSA key fingerprint is SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '[altssh.gitlab.com]:443,[172.65.251.182]:443' (ECDSA) to the list of known hosts . git@altssh.gitlab.com: Permission denied (publickey,keyboard-interactive).
【解决方案2】:

GitLab.com 运行第二个 SSH 服务器,它侦听常用端口 443,该端口不太可能被防火墙。

您所要做的就是编辑您的 ~/.ssh/config 并更改您连接到 GitLab.com 的方式。

Host gitlab.com
 Hostname altssh.gitlab.com
 User git
 Port 443
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/id_rsa.pub

来源:https://about.gitlab.com/2016/02/18/gitlab-dot-com-now-supports-an-alternate-git-plus-ssh-port/

【讨论】:

【解决方案3】:

我尝试了上述方法,但删除了最后一行的 .pub,因为它表示格式不正确。并且成功了。

Host gitlab.com
 Hostname altssh.gitlab.com
 User git
 Port 443
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/id_rsa

【讨论】:

    【解决方案4】:

    你可以试试:

    ssh git@gitlab.com

    它应该打开一个立即关闭的连接。

    如果超时,您可能位于阻止连接的防火墙后面。在这种情况下,您应该添加一个允许您连接的规则。

    【讨论】: