Speeding up OpenSSH sessions with multiplexing

When you’re about to establish an SSH connection to a new host, it usually takes a few seconds before the session is loaded. If you open multiple SSH sessions to the same host, the overhead starts to sum up and you’re waiting for the connection. This might not be a big issue for normal/manual use, but if you’re doing automation via SSH, or a lot of git push/pull operations, this could become a PITA.

Enable OpenSSH multiplexing via config

OpenSSH has a really neat multiplexing feature implemented, which unfortunately is disabled by default. To enable it, you’ve to update your SSH config with the Control* options:

The ControlMaster  option defines whether ssh is listening for control connections and what to do with them. If you set it to auto , ssh will create a control socket at the ControlPath  at the first connection attempt, and then use it automatically for future connections to that host. You can also set it to autoask , so that ssh will ask you about confirmation. The control socket will be existing for ControlPersist  amount of time. You can also set ControlPersist  to yes , so that the multiplexing connection is open in the background indefinitely, until you close it manually.

Control open multiplexing sessions

You can control the multiplexing connections via ssh command.

To check for a multiplexing connection:

To stop a multiplexing connection:

Manually open a multiplexing session

To manually establish a multiplexing connection:

For future SSH connections, you just have to specify the socket:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.