Git SSH "kex_exchange_identification: Connection closed" in CI
By Kaveh Alemi·Latchkey
The remote closed the SSH connection before key exchange even began. This is a transport-level cutoff - a blocked or proxied port 22, a transient rate limit, or a network interruption - not a key or permissions problem.
What this error means
An SSH clone/fetch fails with kex_exchange_identification: Connection closed by remote host and fatal: Could not read from remote repository. It can be intermittent (succeeds on retry) or consistent when port 22 is blocked.
git clone output
kex_exchange_identification: Connection closed by remote host
Connection closed by 140.82.x.x port 22
fatal: Could not read from remote repository.
Diagnose it: depth, refs, or credentials?
Terminal
git rev-parse --is-shallow-repository
git rev-parse --abbrev-ref HEAD # prints HEAD when detached
git log --oneline -3
git remote -v
Common causes
Port 22 blocked or proxied
A firewall or network that does not allow outbound SSH on port 22 closes the connection before the handshake completes.
Transient rate limit or network blip
The host may briefly drop connections under load or rate limiting, so the same command succeeds on a retry.
How to fix it
Use SSH over the HTTPS port (443)
GitHub serves SSH on port 443 via ssh.github.com, which bypasses a blocked port 22.
When the cutoff is intermittent, a bounded retry around the clone clears most blips.
Terminal
for i in 1 2 3; do
git clone git@github.com:org/repo.git && break
echo "ssh clone failed (attempt $i), retrying..."; sleep 5
done
How to prevent it
Allow outbound SSH (port 22), or use ssh.github.com:443 on locked-down networks.
Wrap SSH clones in a bounded retry to absorb transient cutoffs.
Fall back to the HTTPS remote where SSH egress is not permitted.
Frequently asked questions
What causes Git SSH "kex_exchange_identification: connection closed" in CI?
There are 2 common causes: port 22 blocked or proxied and transient rate limit or network blip. A firewall or network that does not allow outbound SSH on port 22 closes the connection before the handshake completes.
How do I fix Git SSH "kex_exchange_identification: connection closed" in CI?
There are 2 fixes depending on which cause you have: use ssh over the https port (443) and retry the transient failure. Work through them in order, since the first is the most common.
What does Git SSH "kex_exchange_identification: connection closed" in CI actually mean?
An SSH clone/fetch fails with kex_exchange_identification: Connection closed by remote host and fatal: Could not read from remote repository.
How do I stop Git SSH "kex_exchange_identification: connection closed" in CI happening again?
Allow outbound SSH (port 22), or use ssh.github.com:443 on locked-down networks. The prevention section lists 3 changes that keep it from recurring.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.
This is a transient network failure, not a bug in your code. Latchkey detects, repairs, and retries it for you.Start free →30-day trial · No credit card
Cookie Preferences
Choose which categories of cookies you want to allow. Essential cookies are always active as they are required for the site to function.
Essential
Required for the site to function.
Functional
Remembers your preferences like selected organization and dashboard settings.
Analytics
Helps us understand how the site is used (Google Analytics).