Then I discovered there was a way to configure SSH to reuse the open TCP connection rather that setting up an new one. This comes with a big advantage as the overhead of creating a new TCP connection is now eliminated. This results in faster connection time and transfer of data.
To configure you will need to edit the SSH config file for the respective user account (~/.ssh/config)
Host x.x.x.xWhat do these options mean?
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 1800
- Host x.x.x.x # the IP/Domain name of the server you are connecting to. You can opt to use the wildcard * but I prefer being specific and offers some security
- ControlMaster auto #The default is no. So you have to specify either "yes","auto","ask","autoask".
- ControlPath ~/.ssh/sockets/%r@%h-%p #Make sure the path exist. Create the folder and secure. %h - target hostname, %r - remote username, &%p - port. Other variables include %L,%l, %n & %u.
- ControlPersist 3600 #How long the the master connection remains open before timing out due to inactivity. Defaults to seconds but can be expressed as 60m or 1hr
You can have multiple blocks
Host 1.1.1.1
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 1800
Host 2.2.2.2.All commands that use SSH, e.g. RSYNC, SCP, SFTP, will benefit from multiplexing. It should be noted that Multiplexing allows a a maximum of 10 open sessions per connection by default. You can increase this number by changing the value of MaxSessions. If you have a large number of connections you might need to change MaxStartups.
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 1800
References