gitlab.com SSH 连接超时

gitlab.com SSH connection timed out

我尝试让 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.

出了什么问题?

你可以试试:

ssh git@gitlab.com

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

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

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/

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

正如 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

我试过上面的方法,但是删除了最后一行的.pub,因为它说格式不正确。并且成功了。

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