0%

解决git报错:ssh:connect to host github.com port 22: Connection timed out

如题,git使用中突然报错

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

通过查阅各种资料,得知原因可能是由于电脑的防火墙或者其他网络原因导致ssh连接方式 端口22被封锁。

解决方法
一:抛弃ssh连接方式,使用http连接。
1
2
git config --local -e
将配置文件的url = git@github.com:username/repo.git一行改为:url = https://github.com/username/repo.git
方法二:如果22号端口不行,那就换一个端口

进入.ssh文件夹

创建一个config文件

将下面的内容复制进去

1
2
3
4
5
6
7
8
9
10
11
12
13
Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

Host gitlab.com
Hostname altssh.gitlab.com
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

保存退出

检查是否成功

1
ssh -T git@github.com

这里要根据它的提示操作,有个地方要输入yes

此时大功告成啦

-------------本文结束感谢您的阅读-------------
技术原创:姚渐新,您的支持将鼓励我继续创作