Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amontalenti/a5b9717901c16163c477ac2cbe2a4d65 to your computer and use it in GitHub Desktop.
Save amontalenti/a5b9717901c16163c477ac2cbe2a4d65 to your computer and use it in GitHub Desktop.
10x SSH connection speedup w/ persistent control masters

SSH Persistent Control Master Config

Add to ~/.ssh/config:

Host *
  # Enable persistent connection multiplexing
  ControlMaster auto
  ControlPath ~/.ssh/sockets/-%r@%h:%p
  ControlPersist 600

Make sure to create the folder for the sockets:

mkdir ~/.ssh/sockets

Now first connection to host will establish persistent daemon connection; subsequent commands will multiplex over existing connection in ~/.ssh/sockets, reducing setup/connect overhead by ~10x.

Demo

First connection establishes persistent control master daemon:

$ time ssh example.com true

real	0m1.687s
user	0m0.066s
sys	0m0.014s

Subsequent connections:

$ time ssh example.com true

real	0m0.162s
user	0m0.053s
sys	0m0.010s

This gets even better if you have to open lots of connections in parallel, or if you have to open and close short-lived connections frequently.

Management commands

Idle connections with no riders are auto stopped after 10 mins (ControlPersist 600) but you can manage connections manually w/ ssh -O:

$ ssh -O check example.com
Master running (pid=40196)
$ ssh -O stop example.com
Stop listening request sent.

See Also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment