首页 > 解决方案 > Gitlab SSH 连接超时,但使用 HTTP(S) 工作正常

问题描述

提示:SSH密钥在我的机器和Gitlab上都配置好了,所以显然不是认证问题,而是连接问题。

当我连接到我的家庭网络并尝试通过 SSH 连接到 Gitlab 时(ssh -v git@gitlab.com),连接超时并失败。然后进程尝试再次连接,现在使用 IPv4,然后连接成功(等待几分钟后),输出如下:

OpenSSH_7.4p1 Debian-10+deb9u7, OpenSSL 1.0.2u  20 Dec 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to gitlab.com [2606:4700:90:0:f22e:fbec:5bed:a9b9] port 22.
debug1: connect to address 2606:4700:90:0:f22e:fbec:5bed:a9b9 port 22: Connection timed out
debug1: Connecting to gitlab.com [172.65.251.78] port 22.
debug1: Connection established.

但是,如果我连接到任何其他网络,则连接成功,产生以下输出:

OpenSSH_7.4p1 Debian-10+deb9u7, OpenSSL 1.0.2u  20 Dec 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to gitlab.com [172.65.251.78] port 22.
debug1: Connection established.

显然这是我的家庭网络或 Gitlab 上的问题,但我已经尝试了一切,并尝试了很多可能的解决方案,但没有成功。

很感谢任何形式的帮助。

标签: gitsshgitlabipv6ipv4

解决方案


我遇到过同样的问题。这是我的网络。我尝试使用http://ipv6now.com.au/pingme.php ping gitlab ,它成功了。当我从本地工作站发出 ping 命令时,它不起作用。我使用我在这里找到的说明更改了我的工作站以更喜欢 ipv4,http://sf-alpha.bjgang.org/wordpress/2012/08/linux-prefer-ipv4-over-ipv6-in-dual-stack-environment -and-prevent-problems-when-only-ipv4-exists/。本质上,我取消注释并将 /etc/gai.conf 中的行从更改 precedence ::ffff:0:0/96 10precedence ::ffff:0:0/96 100


推荐阅读