解决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连接。

git config --local -e
将配置文件的url = [email protected]:username/repo.git一行改为:url = https://github.com/username/repo.git

方法二:如果22号端口不行,那就换一个端口

进入.ssh文件夹

创建一个config文件

将下面的内容复制进去

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

保存退出

检查是否成功

ssh -T [email protected]

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

此时大功告成啦

猜你喜欢

转载自blog.csdn.net/yjxkq99/article/details/128927038