git clone 出现ssh: connect to host github.com port 22: Connection timed out解决方案

物理机服务器,安装git之后,想从githubclone自己的项目运行,ssh key已经配置过, 但在执行git clone命令时出现了如下报错:

1
2
3
4
ssh: connect to host github.com port 22: Connection timed out
fatal: 无法读取远程仓库。

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

解决方案

在系统~/.ssh目录下执行touch config命令新建config文件,并修改文件权限:

1
sudo chmod 600 config

然后在config文件中添加如下内容:

1
2
3
4
5
6
Host github.com
User email@qq.com // 替换成自己的github登录邮箱
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

然后设置:

1
2
git config --global user.name "XXX"
git config --global user.email XXX@xx.com

此时再去执行git clone命令,一切正常。