Speed up repeated SSH/SCP/SFTP connections to the same host by reusing one cached network connection (multiplexing) via ControlMaster/ControlPath/ControlPersist, and detect dead connections with ServerAlive keepalives.

domain: openssh.com · 6 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Add to ~/.ssh/config: `Host *` / ` ControlMaster auto` / ` ControlPath ~/.ssh/sockets/%r@%h:%p` / ` ControlPersist 10m`. ControlPath tokens: %r=remote username, %h=remote hostname, %p=remote port (or use the single hashed token %C instead).
  2. Create the socket directory with restrictive permissions before first use: `mkdir -p -m 700 ~/.ssh/sockets`, matching the ControlPath directory referenced above so shared connections are uniquely and safely identified.
  3. Run `ssh <user>@<host>` once; because ControlMaster is 'auto' this opportunistically creates the control socket if none exists yet. Subsequent `ssh`, `scp`, or `sftp` calls to the same %r@%h:%p reuse that connection and skip the handshake, becoming near-instant.
  4. ControlPersist 10m keeps the master connection alive in the background for 10 minutes after the last client session closes, so short-lived scripted connections do not renegotiate; use 'yes' to persist indefinitely until explicitly closed.
  5. Add keepalives so ssh detects an unresponsive peer instead of hanging: `Host *` / ` ServerAliveInterval 15` / ` ServerAliveCountMax 3`. This sends an encrypted keepalive every 15s and disconnects after 3 unanswered probes (about 45s of unresponsiveness).
  6. Close a multiplexed master explicitly when done: `ssh -O exit <user>@<host>`, or check whether one is running for that destination with `ssh -O check <user>@<host>`.

Known gotchas

Give your agent this knowledge — and 17,100+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans