问题表现¶
可以通过浏览器正常访问github.com
。
命令行中执行 git pull
时出现以下错误:
1
2
|
ssh: connect to host github.com port 22: Operation timed out
fatal: Could not read from remote repository.
|
核心解决步骤¶
第一步:验证 SSH 端口封锁¶
- 预期正常响应:
Connected to github.com...
- 异常响应:
Operation timed out
表示端口 22 被阻断: nc: connectx to github.com port 22 (tcp) failed: Operation timed out
第二步:配置 SSH over 443 端口¶
- 创建 SSH 配置文件
- 写入配置内容
Host github.com
Hostname ssh.github.com
Port 443
User git
第三步:测试新配置¶
- 如果有询问是否修改
known_hosts
, 输入 yes
:
1
2
3
|
This host key is known by the following other names/addresses:
~/.ssh/known_hosts:28: github.com
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
|
- 成功标志:
Hi username! You've successfully authenticated...
补充方案¶
使用 HTTPS 协议代替 SSH¶
1
|
git config --global url."https://github.com/".insteadOf git@github.com:
|