# Why SSH sessions die on your phone, and how QUIC keeps them alive

> Discover why mobile SSH connections disconnect when your phone sleeps or changes networks, and how QUIC connection migration keeps terminal sessions alive.

Source: https://cawide.dev/blog/why-ssh-dies-on-mobile

SSH sessions drop on mobile phones because the Secure Shell protocol depends on a single persistent TCP 4-tuple that breaks whenever your phone sleeps, changes IP addresses, or switches cell towers.

QUIC solves this fundamental limitation through cryptographic Connection IDs and connection migration. When your iPhone moves between Wi-Fi and 5G cellular networks, your terminal connection migrates without resetting the transport state.

## Why does a standard SSH session drop when your phone switches to 5G?

A standard SSH session relies on a single underlying TCP socket. In standard TCP networking, an active connection is uniquely identified by an operating system 4-tuple:

1. Client IP address
2. Client port number
3. Server IP address
4. Server port number

When your iPhone connects to office or home Wi-Fi, the client IP address belongs to your local wireless subnet. When you step outside, walk through an elevator lobby, or drive away, iOS shuts down the Wi-Fi interface and activates cellular 5G data.

This interface handoff assigns your phone a completely new IP address provided by your mobile carrier. The moment the client IP changes, the original TCP 4-tuple becomes invalid. The server continues sending packets to your old Wi-Fi IP address, receives no acknowledgments, and eventually sends a TCP RST or times out.

Because SSH does not possess native connection migration primitives, the client socket closes and your terminal buffer completely freezes.

## How does iOS background execution suspend traditional TCP sockets?

Even if your phone never changes networks, simply putting your iPhone into your pocket often kills an SSH session.

iOS employs aggressive background process management to preserve battery life and thermal headroom:

- When you switch away from an SSH app or press the side button to lock your screen, iOS moves the application into a suspended background state within a matter of seconds.
- While suspended, the app cannot execute CPU instructions or process socket buffers.
- The remote SSH server continues sending TCP keepalive probes (`ServerAliveInterval` or TCP keepalive).
- Because the suspended iOS client cannot acknowledge these incoming packets, the remote host assumes the client dropped off the network.
- The server closes the pseudo-terminal (PTY) and sends SIGHUP to your running foreground process, killing any un-detached compilation, test suite, or AI agent.

Mobile developers often resort to running `tmux` or `mosh` on the host to mitigate this. While `tmux` keeps the process alive, reconnecting still requires manually launching the app, establishing a new SSH handshake, and attaching to the session. Mosh helps with UDP roaming, but lacks modern mutual TLS 1.3 authentication, file browsing APIs, and agent hook integration.

## How does QUIC connection migration keep terminal sessions alive?

Cawide replaces TCP with QUIC, an encrypted transport protocol implemented via iroh that runs on top of UDP.

QUIC separates the concept of a network path from the logical connection identity:

- **Connection IDs**: Instead of relying on the ephemeral IP and port 4-tuple, a QUIC endpoint assigns a cryptographic 64-bit Connection ID to the session.
- **Path validation**: When your phone switches from Wi-Fi to cellular, it sends a QUIC packet from its new cellular IP containing the existing Connection ID along with a PATH_CHALLENGE frame.
- **Zero-reconnect migration**: The Cawide host receives the packet, validates the challenge response, and immediately shifts outgoing traffic to the new IP address. The cryptographic keys and stream offsets remain completely intact.

There is no reconnection delay, no dropped terminal output, and no broken transport handshake.

## How does Cawide recover output when you enter an area with zero cellular service?

What happens when you enter a subway tunnel, a concrete basement, or an airplane with no internet connectivity whatsoever?

In complete connectivity blackouts, no network protocol can transmit packets. However, the architectural difference lies in what happens to your processes and your terminal history while you are offline:

1. **Host-side session persistence**: In Cawide, all terminal sessions run inside real PTY processes managed by the background daemon (`cawide serve`). The daemon decouples the lifetime of the process from the network socket.
2. **Screen snapshot restoration**: While your phone is disconnected, your agents or scripts continue executing on your computer. When connectivity returns, Cawide automatically re-establishes the encrypted QUIC tunnel.
3. **Scrollback replay**: On reconnection, Cawide inspects the stream sequence numbers. If you missed recent log output, Cawide replays the missed terminal buffer or restores the full screen snapshot.

In benchmark tests recorded on Apple Silicon hardware (crates/cawide-core/benches/loopback.rs), keystroke round trip latency measured p50 2.75 ms and p99 14.35 ms across 200 samples. Terminal throughput reached 24 MB/s, and replaying a full 256 KiB scrollback buffer completed in just 31 ms. Loopback benchmark on Apple Silicon (host and app on one machine). Real-world latency adds your network round trip.

## Why does mutual TLS 1.3 with Ed25519 keys eliminate passwords and bastions?

Traditional remote access setups require configuring SSH keys in `~/.ssh/authorized_keys`, forwarding port 22 on your home router, setting up dynamic DNS, or deploying an SSH bastion jump host. Every open port exposes your home or office network to internet-wide automated port scanners.

Cawide takes a completely different security approach:

- **Mutual TLS 1.3**: During pairing via QR code or manual link, your iPhone and your workstation exchange Ed25519 public keys.
- **No passwords or ports**: The host listens on a random UDP port or uses relay servers to facilitate initial peer discovery. You never expose port 22.
- **Strict unauthorized rejection**: Any incoming connection attempt that fails mutual authentication is dropped immediately following the TLS handshake, before any multiplexed stream or shell process can be created.
- **Zero-knowledge relaying**: When direct peer-to-peer UDP hole punching is blocked by symmetric NATs, traffic flows through encrypted relay servers. Relays only inspect encrypted packets and possess no capability to read terminal payloads or decrypt session tokens.

You get a terminal that survives phone sleep, network handoffs, and subway tunnels, while keeping your machine secure without open ports or complex VPNs.

