SSH allows to have a session alive for a while after you've disconnected, so you don't have to initiate the connection next time. Here are the options for ssh config to enable it:
Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 30
ControlMaster
enables the sharing of multiple sessions over a single network connection. When set to auto
, each new attempt checks if the respective connection exists and either uses it or creates new connection.
ControlPath
specifies the path where connection are stored. Make sure that this path exists! That is, create the directory (sockets here, but name it as you want) manually.
ControlPersist
specifies the how long the connection lives after you have disconnected. It accepts time in seconds.
For further clarification on the options use man ssh_config
.
After you add these to your ~/.ssh/config
, only one session will be opened for these three commands.
On my computer it gives 5x speedup: 100 connections in row to some (nearby) host work in 30s without persistent sessions and only 5-6s with them.
P.S. Sometimes (for example, if you changed the network) your existing ssh connections make break and new ones won't establish because the file with the connection does exist. In this case just go to ~/.ssh/sockets
and delete the necessary file manually.