网络技术分享
个人经验记录

Failed to connect to github.com port 443 after ; Recv failure: Connection was reset

报错:

  1. fatal: unable to access ‘https://github.com/youname/projectname.git/’: Failed to connect to github.com port 443 after 21079 ms – 连接超时(21秒)
  2. Recv failure: Connection was reset – 连接被重置

解决方案:

1. 测试网络连接

bash

# 测试是否能访问GitHub

ping github.com

# 测试HTTPS端口

telnet github.com 443

# 或使用curl测试

curl -I https://github.com

2. 检查代理设置

bash

# 查看是否有代理设置

git config –global –get http.proxy

git config –global –get https.proxy

# 如果有代理且不需要,移除它们

git config –global –unset http.proxy

git config –global –unset https.proxy

# 或者设置正确的代理(如果你需要代理)

git config –global http.proxy http://127.0.0.1:1080

git config –global https.proxy http://127.0.0.1:1080

3. 使用SSH替代HTTPS(推荐)

这是最可靠的解决方案:

步骤1:生成SSH密钥

bash

# 生成SSH密钥(如果还没有)

ssh-keygen -t rsa -b 4096 -C “你的邮箱地址”

# 一直按Enter使用默认值

步骤2:将SSH公钥添加到GitHub

bash

# 显示公钥内容

cat ~/.ssh/id_rsa.pub

# 复制显示的全部内容(以ssh-rsa开头)

  1. 登录GitHub
  2. 点击右上角头像 → Settings → SSH and GPG keys
  3. 点击”New SSH key”
  4. 粘贴公钥内容,添加标题(如”My Computer”)

步骤3:更改远程仓库地址为SSH

bash

# 查看当前远程地址

git remote -v

# HTTPS地址改为SSH地址

git remote set-url origin git@github.com:youname/projectname.git

# 验证是否更改成功

git remote -v

# 应该显示git@github.com:youname/projectname.git

步骤4:测试SSH连接

bash

# 测试SSH连接

ssh -T git@github.com

# 如果成功,会显示:Hi youname! You’ve successfully authenticated, but GitHub does not provide shell access.

步骤5:使用SSH推送

bash

# 现在使用SSH推送

git push origin main

赞(0) 打赏
未经允许不得转载:老麻 » Failed to connect to github.com port 443 after ; Recv failure: Connection was reset

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

登录

找回密码

注册