0. 概述

上周有同事说在服务器上的机器拉取 Github 的代码不成功,会超时,我尝试了一遍,确实有这个问题,但是我修改了一下 DNS 地址之后恢复了。 但是,今天我遇到这个问题了,不是在服务器上,而是在本机,推送代码一直超时。

[[email protected]]# git push origin master
ssh: connect to host github.com port 22: Connection timed out
fatal: 无法读取远程仓库。

请确认您有正确的访问权限并且仓库存在。

1. 问题定位

于是我就尝试了一下 SSH 命令看看:

[[email protected]]# ssh -T [email protected] 

ssh: connect to host github.com port 22: Connection timed out

发现确实是同样的问题,所以就打开了 DEBUG 日志分析看看:

[[email protected]]# ssh -v -T [email protected]

OpenSSH_8.3p1, OpenSSL 1.1.1g  21 Apr 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [52.74.223.119] port 22.

看上去就是网络的问题了,这个没有什么思路,于是只能查查资料了。

2. 问题解决

经过简单查找之后发现了一个解决方案,添加一个 SSH 配置:

[[email protected]]# cat ~/.ssh/config
Host github.com
 Hostname ssh.github.com
 Port 443

然后再尝试一下看看:

[[email protected]]# ssh -T [email protected]   

Hi liuliqiang! You've successfully authenticated, but GitHub does not provide shell access.

问题解决!再看下原帖是怎么解释的:

Sometimes, firewalls refuse to allow SSH connections entirely. If using HTTPS cloning with credential caching is not an option, you can attempt to clone using an SSH connection made over the HTTPS port. Most firewall rules should allow this, but proxy servers may interfere

我想可能又是 G×W 的锅了。

3. Ref