Speed up Your SSH Connections for Free

Adding the following directives to your .ssh/config should reduce your SSH connection establishment time significantly:

        ControlMaster auto
        ControlPersist yes
        ControlPath "/tmp/ssh-c-%r@%h:%p"

This works by having all SSH sessions sharing a single “control” connection.

The ControlMaster auto directive tells OpenSSH client to start a control master if one is not already running, otherwise it will reuse a previous one.

The ControlPersist yes directive tells the control master process to continue running in the background even though you’ve exited from the session, allowing subsequent sessions to reuse its connection.

The ControlPath is the control socket rendezvous point for masters and slaves. If you’re on a shared host, you might want to set it to a private location such as in your ~/.ssh/ directory instead of /tmp.

In my case, I stuck these into the wildcard Host section:

Host *
        Compression yes
        ServerAliveInterval 60
        ServerAliveCountMax 5
        ControlMaster auto
        ControlPersist yes
        ControlPath "/tmp/ssh-c-%r@%h:%p"

I’ve always known that OpenSSH had this functionality, but hadn’t bothered to try it out until now and it’s sooo very handy!



Comments are closed.