Speed Up Your SSH Connections

SSH’ing into a server takes a few seconds. This doesn’t seem like much but when your logging into and out of servers all day removing those seconds makes life a little easier.

The following configuration will create a master connection where all the crypto negation and key exchange takes place. This master connection can then be reused for any subsequent connection meaning that the connections are near instant.

Put the following configuration into your SSH config file at ~/.ssh/config:

Host *
  ControlPath    ~/.ssh/%C.sock
  ControlMaster  auto
  ControlPersist 10m

The socket file will get written into your .ssh directory and the socket will persist after logout for 10m. You can change that timeout period to anything you like with the ControlPersist option.

I measured connections to a remote server and got the following:

Time
Without Socket 2.205s
With Socket 0.065s