ssh -T git@github.com 出现Connection reset错误

本文介绍了一种解决Hexo博客上传至Github时遇到的连接失败问题的方法,通过调整Windows防火墙规则,允许SSH端口22的入站连接,成功解决了Connection reset by peer的错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概述

​ 前几天在用Hexo发布博客文章时,遇到上传Github失败问题,主要提示为

Connection reset by 52.74.223.119
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

问题发现

​ 由于已经在Git bash中配置过SSH免密访问,且已正常使用过也没有进行修改,所以排除SSH key配置问题。怀疑是无法连接到github.com,尝试执行ssh -T git@github.com得到如下结果:

$ ssh -T git@github.com
Connection reset by 52.74.223.119 port 22

​ 竟然真的无法SSH连接到github.com???增加-v选项查看一下详细信息,反馈如下:

$ ssh -T -v git@github.com
OpenSSH_8.0p1, OpenSSL 1.1.1c  28 May 2019
debug1: Reading configuration data /c/Users/Alder/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [52.74.223.119] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Alder/.ssh/id_rsa type 0
debug1: identity file /c/Users/Alder/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/Alder/.ssh/id_dsa type -1
debug1: identity file /c/Users/Alder/.ssh/id_dsa-cert type -1
debug1: identity file /c/Users/Alder/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/Alder/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/Alder/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/Alder/.ssh/id_ed25519-cert type -1
debug1: identity file /c/Users/Alder/.ssh/id_xmss type -1
debug1: identity file /c/Users/Alder/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.0
debug1: Remote protocol version 2.0, remote software version babeld-d45c1532
debug1: no match: babeld-d45c1532
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
Connection reset by 52.74.223.119 port 22

问题解决

​ 在Windows系统下,打开控制面板->系统和安全->Windows Defender 防火墙->高级设置,选择入站规则,点击新建规则,选择端口,在特定本地端口写入22,连续选择下一步三次,输入一个名称(随意命名规则),点击完成,然后再执行命令得到如下格式结果:

$ ssh -T git@github.com
Hi XXX! You've successfully authenticated, but GitHub does not provide shell access.

​ 再尝试发布Hexo博客到Github就可以正常上传了…暂时不知道这其中的原理,即使将刚添加的规则删除了,再打开新的Git bash窗口也不会出现Connection reset错误了。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值