解决方案

【git】解决git报错:ssh:connect to host github.com port 22: Connection timed out 亲测有效

2024-01-18 11:16:34 michael007js 104

【git】解决git报错:ssh:connect to host github.com port 22: Connection timed out 亲测有效




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

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

解决方法

一:抛弃ssh连接方式,使用http连接。

git config --local -e
将配置文件的url = git@github.com: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 git@github.com

在这里插入图片描述

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


首页
关于博主
我的博客
搜索