Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Fix SSH Tunnel Freezes While Internet Is Working

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

When your internet connection is working but an SSH session or tunnel freezes, the cause is typically one of the following:

For general usage of SSH tunnels, please refer to SSH Tunnel and Tips on SSH.

Quick Escape: Kill a Frozen SSH Session

If your terminal is completely unresponsive and ignores Ctrl+C:

  1. Press Enter.

  2. Type ~. (tilde followed by a period). The escape sequence is only recognized at the start of a line (which is why you press Enter first) and is disabled if EscapeChar none is set. In nested SSH sessions, ~~. closes the inner session.

  3. If you use a multiplexed connection or a background tunnel, terminate it from another terminal.

    ssh -O exit <remote-host>
    # or check matching processes first and then kill them
    pgrep -af "ssh .*<remote-host>"
    pkill -f "ssh .*<remote-host>"

Diagnosis

When does it freeze?

Likely cause

Fix

After being idle for a few minutes

NAT / firewall state timeout

ServerAliveInterval in ~/.ssh/config

Immediately when transferring data or printing large output

MTU / PMTU blackhole

Lower the MTU or enable MTU probing

After the laptop sleeps, locks, or changes networks

ControlMaster stuck on a dead connection

Keepalives + ssh -O exit <remote-host>

1. Freezes When Idle (NAT / Firewall State Timeout)

Home routers, mobile hotspots and intermediate firewalls maintain state tables for TCP connections. If a connection sends no traffic for a while (often a few minutes), the router might silently drop the connection tracking entry without sending a FIN or RST. When you type again, packets are discarded and SSH hangs indefinitely.

The fix is to enable client keepalives in ~/.ssh/config (or pass -o ServerAliveInterval=15 on the command line).

Host *
    ServerAliveInterval 15
    ServerAliveCountMax 3

2. Freezes During Data Transfer or Large Output (MTU / PMTU Blackhole)

If small commands (e.g., date, pwd) work fine but commands with large output (e.g., cat file, git push) or high-bandwidth port forwarding freeze the tunnel instantly, the cause is likely a path MTU blackhole.

You can confirm the issue by sending non-fragmentable pings of different sizes. -s 1372 is the payload size, which results in a 1400-byte packet after adding the 28-byte IP and ICMP headers. Lower -s until pings go through to find the path MTU.

# Linux
ping -M do -s 1372 <host>
# macOS
ping -D -s 1372 <host>

Fixes:

3. Freezes After Sleep / Lock / Network Switch (ControlMaster)

If you use SSH connection multiplexing (ControlMaster auto), the master process might still be alive after the machine sleeps or switches networks (e.g., from Wi-Fi to Ethernet), while its underlying TCP connection is dead. Subsequent SSH commands and forwarded ports are multiplexed onto the dead connection and hang.

Fixes:

4. Make Sessions and Tunnels Survive Network Drops

5. Other Causes