How to use multiplexing in SSH
Multiplexing allows a single SSH connection to be shared by multiple sessions. The connection could be set to persist for a set time and then reused for fast reconnection to the server.
Related: How to speed up SSH authentication
Sharing SSH sessions in a single connection via multiplexing could be configured in the user's SSH client configuration file.
Steps to share and reuse SSH connection via multiplexing:
-
Launch terminal.
-
Open SSH client configuration file for your user using your preferred text editor.
$ vi ~/.ssh/config
-
Select the host(s) that you want to implement multiplexing.
host *
* applies configuration for all hosts. Other possible host options:
example.com *.example.com 192.168.100.10 192.168.100.*
-
Enable multiplexing for the selected host(s).
host * controlmaster auto
-
Set how long do you want the multiplexing session to persist.
host * controlmaster auto controlpersist 10m
-
Set path and filename for controlmaster file.
host * controlmaster auto controlpersist 10m controlpath ~/.ssh/muxmasters/%C
Create folder if doesn't exist.
$ mkdir -p ~/.ssh/muxmasters
-
Check for existing control file on local host.
$ ls ~/.ssh/muxmasters
-
Log in to a remote host.
$ ssh 192.168.111.159 -- hostname [email protected]'s password: remotehost
-
Check for created control file to confirm.
$ ls ~/.ssh/muxmasters 598a7155ff90f076057fb265730c6ffe5997d4bb
-
Log in again to the same host to test.
$ ssh 192.168.111.159 -- hostname host
Should be without password and very fast as long as you log in again within the controlpersist time value.