> 技术文档 > ssh: connect to host github.com port 22: Connection timed out _拉取gitlab代码提示 port22 connection timed out

ssh: connect to host github.com port 22: Connection timed out _拉取gitlab代码提示 port22 connection timed out

1. 前言
这里记录一个使用 Git 时遇到的问题,当然不是 Git 的问题,经我网上查找答案后,可能是系统防火墙的问题。同时网友也给出了可以解决问题的方法。

2. 解决方法

# Git 请求远程服务器超时
$ git clone git@github.com:xxxxx/xxxx.git my-awesome-proj
Cloning into \'my-awesome-proj\'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

# 这段命令应该也会超时
$ ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out

# 但是这段命令应该不会。如果未使用 https 来连接的,它会叫你输入 fingerprint,
# 注意不是输入这个单词,控制台会说,虽然是英文
$ ssh -T -p 443 git@ssh.github.com
Hi xxxx! Youve successfully authenticated, but GitHub does not provide shell access.

# 覆盖 ssh 配置
$ vim ~/.ssh/config

# 如果已经有配置文件了,在其下面添加这段文字

Host github.com  Hostname ssh.github.com  Port 443

# 然后来测试一下,这里是成功了,如果之前是在 IDE 里面发现超时的,可以使用 ssh 来连接了,
# https 貌似还是不行,至少在我电脑上是这样的
$ ssh -T git@github.com
Hi xxxxx! You\'ve successfully authenticated, but GitHub does not
provide shell access.