SSH to GitHub connects, then the server closes or resets the connection
kex_exchange_identification: Connection closed by remote hostShort answer
The TCP connection opened but something hung up before SSH finished its handshake. Either a network device between you and the server is cutting port 22 (firewall, VPN, proxy), or your own server's sshd is refusing new unauthenticated connections. Try GitHub on port 443 first; on your own server check MaxStartups.
Fix it fast
1Find out which cause you have
Run one verbose attempt and note how far it gets. Then run the same test on port 443. If 443 works and 22 does not, the fault is on the network path.
ssh -vT git@github.com ssh -T -p 443 git@ssh.github.com2Match what you see, then jump to its fix
- 1
Port 22 fails after connecting while the port 443 test prints the greeting.A firewall, VPN or proxy cuts port 22Fix - 2
The failure only happens for hosts matched by a Host block that sets a proxy, or by a Host * block.A ProxyCommand or ProxyJump line sends the connection somewhere elseFix - 3
The failure is on a server you run, often when CI or many developers connect at once.Your own git server is dropping unauthenticated connectionsFix
- 1
What does the error look like?
kex_exchange_identification: Connection closed by remote hostConnection reset by 140.82.112.4 port 22fatal: Could not read from remote repository.
Cause 1 of 3
A firewall, VPN or proxy cuts port 22
1Check
GitHub documents port 443 for exactly this case, because most firewalls allow it. Turning the VPN off for one test shows whether it is the culprit.
ssh -T -p 443 git@ssh.github.com2Fix
Route github.com to ssh.github.com on port 443 in your ssh config.
# ~/.ssh/config
Host github.com
Hostname ssh.github.com
Port 443
User git3Verify
The normal command works without extra flags.
ssh -T git@github.comConfirmed by docs.github.com
Cause 2 of 3
A ProxyCommand or ProxyJump line sends the connection somewhere else
1Check
ssh uses the first value it finds for each setting, and a ProxyCommand or ProxyJump in a general block can apply to GitHub too.
grep -n -i -E "^host|proxycommand|proxyjump" ~/.ssh/config /etc/ssh/ssh_config2Fix
Turn the proxy off for the GitHub block. The value none disables it, and host-specific blocks must come before general ones.
Host github.com
ProxyCommand none
ProxyJump none
Host *
# general defaults go last3Verify
Connect again and read the verbose output.
ssh -vT git@github.comConfirmed by man.openbsd.org
Cause 3 of 3
Your own git server is dropping unauthenticated connections
1Check
sshd drops new unauthenticated connections once MaxStartups is reached (default 10:30:100), and newer versions also refuse addresses that look like attacks (PerSourcePenalties) or cap per-source connections (PerSourceMaxStartups).
sudo grep -i -E "maxstartups|persource|logingracetime" /etc/ssh/sshd_config2Fix
Raise MaxStartups to fit your real peak, set a per-source limit if you use one, then reload sshd.
# /etc/ssh/sshd_config
MaxStartups 30:30:1003Verify
Repeat the failing operation from several clients at once and watch the server log.
ssh -vT git@your-git-server.example.comConfirmed by man.openbsd.org
How do I stop it coming back?
- Keep the port 443 block in ~/.ssh/config for networks that filter SSH.
- Limit parallel git jobs in CI so they do not open dozens of connections at the same moment.
- On your own servers, change sshd limits deliberately and keep them in version control.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Security
Git over SSH to GitHub hangs and times out on port 22
fatal: Could not read from remote repository.
A timeout on port 22 means your packets never got an answer: a firewall, hotel or office network, or proxy is dropping SSH.
3 causes, each with a fixSecurity
Entra ID token request fails: the request body must contain the parameter 'grant_type'
AADSTS900144: The request body must contain the following parameter: 'grant_type'.
The token endpoint did not find grant_type in the form body of your POST.
3 causes, each with a fixSecurity
Angular HttpClient does not add the X-XSRF-TOKEN header to a request
403 Forbidden on POST, PUT or DELETE while GET works
Angular copies the XSRF-TOKEN cookie into an X-XSRF-TOKEN header only for mutating requests to the same origin, and only when the cookie is readable by script.
5 causes, each with a fixSecurity
An [Authorize] endpoint rejects a request with a bearer token
Authorization Header sent: no Bearer token sent.
An [Authorize] endpoint without a policy name requires an authenticated user.
4 causes, each with a fixSecurity
ASP.NET Core API rejects an Angular user's token: the signature key was not found
401 Unauthorized
The API looked for the key named by the token's kid in the key set it downloaded from your Authority, and the key was not there.
4 causes, each with a fixSecurity
ASP.NET Core rejects the token before checking it: IDX12741, three segments expected
401 Unauthorized
IDX12741 means the string the API pulled out of the Authorization header is not shaped like a JWT: a signed token has three dot-separated parts and an encrypted one has five.
3 causes, each with a fix