Git over SSH to GitHub hangs and times out on port 22
ssh: connect to host github.com port 22: Connection timed outShort answer
A timeout on port 22 means your packets never got an answer: a firewall, hotel or office network, or proxy is dropping SSH. GitHub accepts SSH on port 443 at ssh.github.com, so route github.com there in ~/.ssh/config. If the network blocks SSH altogether, switch the remote to HTTPS.
Fix it fast
1Find out which cause you have
Test GitHub's SSH endpoint on port 443. If this prints the greeting while plain ssh -T git@github.com hangs, the network is blocking port 22.
ssh -T -p 443 git@ssh.github.com2Match what you see, then jump to its fix
- 1
The port 443 test above succeeds and the port 22 one hangs.A firewall blocks outgoing port 22Fix - 2
You already added Port 443 and it still times out.Port 443 is set but the hostname is still github.comFix - 3
Port 443 over SSH also times out, but a browser reaches github.com.A proxy or filter drops SSH on every portFix
- 1
What does the error look like?
ssh: connect to host github.com port 22: Connection timed outfatal: Could not read from remote repository.
Cause 1 of 3
A firewall blocks outgoing port 22
1Check
Most firewalls allow 443. Run the port 22 test with a short timeout so it fails fast.
ssh -o ConnectTimeout=10 -T git@github.com2Fix
Send all github.com SSH traffic to ssh.github.com on port 443 through your ssh config. Your remote URLs stay the same.
# ~/.ssh/config
Host github.com
Hostname ssh.github.com
Port 443
User git3Verify
The greeting appears. The first time, ssh may ask about the host key; answer yes only if the fingerprint matches one GitHub publishes.
ssh -T git@github.comConfirmed by docs.github.com
Cause 2 of 3
Port 443 is set but the hostname is still github.com
1Check
GitHub serves SSH on 443 only at ssh.github.com. The name github.com does not answer SSH on that port.
grep -n -A4 "Host github.com" ~/.ssh/config2Fix
Add the Hostname line, or clone with the full ssh:// URL for a one-off test.
git clone ssh://git@ssh.github.com:443/YOUR-USERNAME/YOUR-REPOSITORY.git3Verify
The clone starts without a timeout.
git -C YOUR-REPOSITORY remote -vConfirmed by docs.github.com
Cause 3 of 3
A proxy or filter drops SSH on every port
1Check
GitHub notes that proxy servers may interfere with SSH on 443. Check whether your ssh config already forces a proxy hop.
grep -n -i -E "proxycommand|proxyjump" ~/.ssh/config /etc/ssh/ssh_config2Fix
Use HTTPS instead. It works behind firewalls and proxies. For a private repository, enter a personal access token when Git asks for a password.
git remote set-url origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git3Verify
Fetch from the remote.
git fetch originConfirmed by docs.github.com
How do I stop it coming back?
- Keep the port 443 block in ~/.ssh/config on laptops that move between networks.
- Use ConnectTimeout in tests so a blocked port fails in seconds instead of minutes.
- Know the HTTPS URL of each repository as a fallback.
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
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 fixSecurity
A Microsoft Entra access token shows Invalid Signature when you check it yourself
Tokens that a Microsoft API receives might not always be a JWT that can be decoded
A token issued for Microsoft Graph is not meant for you to validate, so a failed signature check is expected.
2 causes, each with a fix