Sample output
$ time ssh devbox echo ok
ok
ssh devbox echo ok 0.02s user 0.01s system 4% cpu 0.041 total
$ time ssh devbox echo ok # without multiplexing
ok
ssh devbox echo ok 0.03s user 0.02s system 2% cpu 1.820 total
The first timing is a multiplexed connection reusing an existing socket: 41 milliseconds. The second is a cold connection with full TCP and key exchange: 1.8 seconds. The difference compounds fast when you run scp, rsync, or git push against the same host repeatedly.
When you would reach for it
You SSH into the same machine dozens of times a day, deploying code, tailing logs, running one-off commands. Each connection pays the full cost of TCP setup, key exchange, and authentication. With multiplexing, the first connection pays that cost once, and every subsequent connection to the same host piggybacks on it in milliseconds. The effect is most visible over high-latency links, through bastion hosts, or when a deploy script opens several SSH sessions in quick succession.
Gotchas
- The socket directory (
~/.ssh/sockets/) must exist before the first connection. Create it withmkdir -p ~/.ssh/sockets. SSH will not create it for you and will silently fall back to non-multiplexed connections. - If the master connection drops (network interruption, laptop sleep), every session sharing that socket hangs or dies. The
-o ServerAliveInterval=60option helps the master detect a dead link sooner. - Multiplexed connections share the master’s authentication. If you SSH as one user and then try to connect as a different user to the same host on the same port, the
%rtoken inControlPathkeeps the sockets separate. Drop%rand you get confusing authentication failures. - Some older jump hosts or hardened servers disable multiplexing on their end with
MaxSessions 1insshd_config. The connection will still work, but each session opens a new channel negotiation, and the speed benefit shrinks.
Variants
$ ssh -O check devbox
Check whether a master socket exists for this host. Prints the PID of the master process or reports that no socket is available. Useful for debugging when multiplexing seems to not be working
$ ssh -O exit devbox
Tear down the master connection and remove the socket. Use this before changing SSH config or when you need a clean reconnection. This closes all sessions sharing that socket, so check first
$ cat >> ~/.ssh/config <<'BLOCK'
Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 600
BLOCK
Move the options into your SSH config so every connection benefits without typing flags. The Host * block applies to all hosts. This is how most people use multiplexing in practice