Git hangs for a while, then gives up:

ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

Your key is not the problem. The connection never got far enough to offer one. Something between you and GitHub is dropping traffic on port 22, which is normal on corporate networks, many hotel and airport networks, and some mobile hotspots.

GitHub publishes an SSH endpoint on port 443 for exactly this. Everything below was tested with OpenSSH 10.3 and Git 2.55.0.

Read the Error Before Fixing It

The wording tells you which problem you have, and they need different fixes.

Connection timed out

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

Packets are being silently dropped, usually by a firewall. This is the case this guide fixes.

Connection refused

ssh: connect to host github.com port 22: Connection refused

Something actively rejected the connection rather than ignoring it. Often a local proxy or VPN client. The port 443 route below usually still works.

Permission denied (publickey)

git@github.com: Permission denied (publickey).

The network is fine and you reached GitHub. This is an authentication problem, so go to Fix Permission Denied (publickey) instead.

Confirm the Port Is Blocked

Test the two ports directly:

ssh -T -o ConnectTimeout=10 git@github.com
ssh -T -o ConnectTimeout=10 -p 443 git@ssh.github.com

If the first times out and the second answers, you have your diagnosis:

Hi you! You've successfully authenticated, but GitHub does not provide shell access.

That sentence is success. It is what a working GitHub SSH connection looks like, on either port.

The Hostname Matters, Not Just the Port

The SSH endpoint is a different host, ssh.github.com. Pointing SSH at github.com on 443 reaches the web server instead, which speaks HTTPS and hangs up:

ssh -T -p 443 git@github.com
Connection closed by 140.82.116.3 port 443

Use ssh.github.com for port 443. This trips up people who change only the port.

Make It Permanent

Add this to ~/.ssh/config, creating the file if it does not exist:

Host github.com
  HostName ssh.github.com
  Port 443
  User git

That keeps every git@github.com:owner/repo.git remote you already have working, with no URL changes, because SSH rewrites the destination before connecting.

Set the permissions SSH expects, or it ignores the file:

chmod 600 ~/.ssh/config

Then verify Git itself, not just SSH:

git ls-remote git@github.com:torvalds/linux.git HEAD
93f51579e7df248780214094418f205253383cc5	HEAD

A hash means Git is going over port 443 and working. Yours will differ, since that repository moves.

If 443 Is Also Blocked

Some networks allow only proxied HTTPS. Switch that repository to an HTTPS remote and authenticate with a token:

git remote set-url origin https://github.com/you/your-repo.git

Then follow Fix: Support for Password Authentication Was Removed, since your account password will not work.

What Not to Do

  • Do not regenerate your SSH key. A timeout happens before any key is offered, so a new key changes nothing.
  • Do not disable host key checking. StrictHostKeyChecking=no does not open a blocked port, and it removes a real protection.
  • Do not add Port 443 to github.com without changing HostName. That reaches the web server, as shown above.
  • Do not assume it is GitHub. Check GitHub status first if every route fails, but a timeout on 22 with 443 working is your network.

Verify

ssh -T git@github.com
git ls-remote git@github.com:you/your-repo.git HEAD

The first prints the “successfully authenticated” line, the second prints a hash. Both go over 443 now, and neither needed a change to any remote URL.

References