How to fix Connection reset by port 22 for git local connection to github remote?


My local computer is using win10, gitbash client, before the local repository and github remote repository can communicate normally via ssh in both directions(pull/clone or push etc), but this time when I pull the remote code to update locally, I get an error.

git pull origin main
Connection reset by port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

I then tried the following command to see if it worked.

 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
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to [] 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 as 'git'
debug1: SSH2_MSG_KEXINIT sent
Connection reset by port 22

It was also tested using the following command.

正在 Ping [] 具有 32 字节的数据:
来自 的回复: 字节=32 时间=222ms TTL=44
来自 的回复: 字节=32 时间=222ms TTL=44
来自 的回复: 字节=32 时间=222ms TTL=44
来自 的回复: 字节=32 时间=222ms TTL=44 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
最短 = 222ms,最长 = 222ms,平均 = 222ms

Also I have tried regenerating the ssh key and then copying the public key correctly into the ssh configuration of my GitHub account as well, the local computer .ssh/config file reads as follows

  User git
  IdentityFile ~/.ssh/id_rsa
  ForwardAgent yes

The result is still unsuccessful.
Does it seem to be connected properly? What can I do to fix it?


ssh -vT [email protected] -A: you are not supposed to use agent forwarding with itself.

The test should be:

# Attempt to SSH in to github
  ssh -T [email protected]
> Hi USERNAME! You've successfully authenticated, but GitHub does not provide
> shell access.

Check the "Using SSH agent forwarding" documentation and see if it applies to your case.

Note: /c/Users/Administrator/.ssh/config: it is best practice to not use your Windows Adminnistrator account, but rather your personal named account with which you initially logged to your Windows session.

Answered By – VonC

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published