我本地电脑使用的是win10,gitbash客户端,之前本地仓库和github远程仓库可以通过ssh双向正常通信(pull/clone或者push等),但是这次当我pull远程代码到本地更新时,我出现错误。
git pull origin main
Connection reset by 140.82.112.4 port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
然后我尝试了以下命令看看它是否有效。
ssh -vT [email protected] -A
OpenSSH_8.3p1, OpenSSL 1.1.1g 21 Apr 2020
debug1: Reading configuration data /c/Users/Administrator/.ssh/config
debug1: /c/Users/Administrator/.ssh/config line 2: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [140.82.112.4] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Administrator/.ssh/id_rsa type 0
debug1: identity file /c/Users/Administrator/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.3
debug1: Remote protocol version 2.0, remote software version babeld-25270101
debug1: no match: babeld-25270101
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
Connection reset by 140.82.112.4 port 22
还使用以下命令进行了测试。
ping github.com
正在 Ping github.com [140.82.112.4] 具有 32 字节的数据:
来自 140.82.112.4 的回复: 字节=32 时间=222ms TTL=44
来自 140.82.112.4 的回复: 字节=32 时间=222ms TTL=44
来自 140.82.112.4 的回复: 字节=32 时间=222ms TTL=44
来自 140.82.112.4 的回复: 字节=32 时间=222ms TTL=44
140.82.112.4 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 222ms,最长 = 222ms,平均 = 222ms
我也尝试重新生成 ssh 密钥,然后将公钥正确复制到我的 GitHub 帐户的 ssh 配置中,本地计算机
.ssh/config
文件读取如下
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
ForwardAgent yes
结果还是不成功。
看起来连接正确吗?我可以做什么来修复它?
ssh -vT [email protected] -A
:您不应该将代理转发与 github.com
本身一起使用。
测试应该是:
# Attempt to SSH in to github
ssh -T [email protected]
> Hi USERNAME! You've successfully authenticated, but GitHub does not provide
> shell access.
查看“使用 SSH 代理转发”文档,看看它是否适用于您的情况。
注意:
/c/Users/Administrator/.ssh/config
:最佳做法是不要使用您的 Windows 管理员帐户,而是使用您最初登录 Windows 会话时使用的个人指定帐户。
对于可能在没有任何变化的情况下随机遇到此问题的人的新答案:只需重新启动计算机/笔记本电脑即可。
这对我有用