Sub topic 13
Connecting over port 443 when port 22 is blocked
This chapter assumes you have an SSH key registered with GitHub and that ssh -T [email protected] works on at least one network. You should also be comfortable editing ~/.ssh/config.
Why port 22 sometimes fails
SSH normally connects to port 22. Some corporate firewalls, hotel networks, and public Wi-Fi hotspots block outbound traffic on that port but allow HTTPS traffic on port 443. When that happens, SSH operations hang or fail even though your key is correct.
GitHub runs an SSH server on port 443 at a separate hostname, ssh.github.com. You can reach it with the same key and the same account. Only the host and port change.
Test the alternate endpoint
Test it before you change any configuration. The -p option sets the port.
ssh -T -p 443 [email protected]On success, GitHub replies that you have successfully authenticated but that it does not provide shell access. This is the same message you get on port 22. If this command also fails, the network is blocking SSH-style traffic on 443, and HTTPS remotes with a token are your fallback.
The first time you connect to ssh.github.com, SSH may ask you to confirm the host fingerprint. Compare it with the fingerprints published in GitHub's documentation before you answer yes.
Make it permanent in ~/.ssh/config
Typing the port every time is impractical, and Git does not let you pass -p to git push. Instead, tell SSH to rewrite the connection for github.com.
Host github.com
HostName ssh.github.com
Port 443
User gitWith this entry, ssh still sees the name github.com on the command line, but it connects to ssh.github.com on port 443. Your existing remote URLs, such as [email protected]:OWNER/REPO.git, keep working without edits.
If you already have a Host github.com block from the earlier chapter on managing keys, do not add a second one. Merge the lines into the existing block so you keep IdentityFile and IdentitiesOnly.
Host github.com
HostName ssh.github.com
Port 443
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yesRun the normal test again to confirm that the rewrite works.
ssh -T [email protected]Common problems
| Symptom | Likely cause | Fix |
|---|---|---|
| Timeout on port 22 only | Firewall blocks port 22 | Add the port 443 config |
| Timeout on 443 too | Network inspects or blocks SSH traffic | Use an HTTPS remote with a token |
| Wrong key offered | Config block missing `IdentitiesOnly yes` | Merge key settings into the same `Host` block |
| Fingerprint prompt repeats | `known_hosts` has no entry for `ssh.github.com` | Accept once after verifying the fingerprint |
Exercise
Your git push over SSH hangs at the office, but works at home. ssh -T -p 443 [email protected] succeeds at the office. What ~/.ssh/config entry lets you keep using [email protected]:OWNER/REPO.git without changing the remote?
Show answer
Add a Host github.com block with HostName ssh.github.com, Port 443, and User git. SSH then connects to ssh.github.com on port 443 whenever Git uses the github.com remote.