Improving the SSH connect time with shared sessions

If you find yourself frequently reconnecting to the same servers, you can save some time by using shared sessions. Shared sessions are very easy to enable.

These steps work on Mac OS and most flavours of Linux.

  1. Open your .ssh/config or create it if you don’t have one.
    nano ~/.ssh/config
  2. Paste the following lines:
    Host *
     ControlMaster auto
     ControlPath /tmp/%r@%h:%p
     ControlPersist yes
  3. Save the file by hitting CTRL+O and confirming with return.

If you are using a wonky flavour of Linux you may have to adjust the /tmp path to something more suitable.


  • By reusing an existing connection, it saves file descriptors, and in turn power, baby seals and kittens, and most of all it is also faster than opening new connections.
  • It does not require new authentication, so it saves the time it takes to type your password, and the time for the challenge-response to take place.
  • Since you do not have to authenticate again, you can take advantage of you shell’s power features to auto-complete remote paths for SCP, SFTP or rsync over SSH.


Just like SSH agents, there is one major side-effect to take into account: new remote sessions can be opened without a password. Never use such a feature on a public computer if you are used to temporarily leave running sessions: here, locking them would not protect other people to get a shell access to your remote account!

Leave a Reply

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