Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

Git over SSH to GitHub hangs and times out on port 22

Errorssh: connect to host github.com port 22: Connection timed out

Short 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.

  • Applies to OpenSSH 9.x and 10.x, Git 2.4x, GitHub.com
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.com
  2. 2Match what you see, then jump to its fix

    1. 1The port 443 test above succeeds and the port 22 one hangs.A firewall blocks outgoing port 22Fix
    2. 2You already added Port 443 and it still times out.Port 443 is set but the hostname is still github.comFix
    3. 3Port 443 over SSH also times out, but a browser reaches github.com.A proxy or filter drops SSH on every portFix

What does the error look like?

  • ssh: connect to host github.com port 22: Connection timed out
  • fatal: 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.com

2Fix

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 git

3Verify

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.com

Confirmed by docs.github.com

Did this fix it?

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/config

2Fix

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.git

3Verify

The clone starts without a timeout.

git -C YOUR-REPOSITORY remote -v

Confirmed by docs.github.com

Did this fix it?

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_config

2Fix

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.git

3Verify

Fetch from the remote.

git fetch origin

Confirmed by docs.github.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.