Developers
SSH and Git time out on a Mac
SSH and Git need a working TCP connection to the server. A network that blocks port 22, a broken IPv6 path or a proxy can stop them.
Symptoms
git pushorgit clonewaits, then shows “Operation timed out”.sshshows “Connection timed out” on one network but works on another.- An SSH session freezes after some idle minutes.
- HTTPS Git remotes work, but SSH remotes do not.
Likely causes
- Port 22 is blocked. Some company, hotel and public networks block SSH. GitHub says that firewalls sometimes refuse SSH connections.
- A broken IPv6 path. The Mac tries IPv6 first. If IPv6 does not work, the connection waits.
- Idle connections close. A router or firewall can drop a connection that sends no data for some time.
- A proxy is necessary. HTTPS Git on a company network can need
http.proxyor proxy variables.
How to check
Connect with verbose output. The last lines show where the connection stops.
ssh -vT git@github.comTest the TCP port alone, with a 5-second timeout.
nc -vz -G 5 github.com 22Try IPv4 only. If this works, the IPv6 path is the problem.
ssh -4 -T git@github.comTest GitHub's SSH service on port 443.
ssh -T -p 443 git@ssh.github.comShow Git's proxy setting and your proxy variables.
git config --get http.proxy env | grep -i proxy
How to fix it
If port 22 is blocked, use SSH over port 443 for GitHub. Add this block to
~/.ssh/config.Host github.com Hostname ssh.github.com Port 443 User gitIf IPv6 fails, use IPv4 for that host. Add
AddressFamily inetto its block in~/.ssh/config.To keep idle sessions open, send a message every 60 seconds. Add
ServerAliveInterval 60to the host block.To stop long waits, add
ConnectTimeout 10to the host block.For HTTPS remotes behind a proxy, set Git's proxy.
git config --global http.proxy http://proxy.example.com:8080As a test, use the HTTPS URL of the repository instead of the SSH URL.
With Kilobat
Kilobat's connection check tests IPv4 and IPv6 separately, so a broken IPv6 path gets a clear answer.
kilobat why github.comSee the open connections of one process.
kilobat destinations --pid 12345
Questions
Why does ssh -4 work when plain ssh does not?
The Mac tried IPv6 first, and the IPv6 path did not work. With -4, ssh uses IPv4 only.
What does ServerAliveInterval do?
ssh sends a message through the connection after that many seconds without data. The default is 0, which sends none.
Sources
- GitHub Docs: Using SSH over the HTTPS port
- ssh(1) and ssh_config(5), man page installed with macOS 27.2
- nc(1), man page installed with macOS 27.2
- git-config(1), http.proxy, man page installed with macOS 27.2 (Git 2.56)
Sources checked on 29 October 2026. Man pages are the ones installed with macOS; open one with man <name> in Terminal.