SSH (Secure Shell) is a powerful tool for secure remote access and file transfer. Beyond its basic functionality, SSH offers advanced features like multiplexing, which allows multiple SSH sessions to share a single network connection. This can speed up operations, reduce connection overhead, and simplify session management.
Multiplexing in SSH can be particularly useful when performing multiple operations on a remote server. Instead of establishing a new connection for each operation, you can reuse an existing connection, making tasks faster and more efficient. This is especially beneficial in scripts or automated tasks where multiple SSH commands might be run in quick succession.
SSH multiplexing is achieved using the ControlMaster, ControlPath, and ControlPersist configuration options in the SSH client. These options allow you to set up and manage master and client sessions.
Related: How to accelerate SSH authentication
$ vi ~/.ssh/config
host *
* applies configuration for all hosts. Other possible host options:
example.com *.example.com 192.168.100.10 192.168.100.*
host * controlmaster auto
host * controlmaster auto controlpersist 10m
host * controlmaster auto controlpersist 10m controlpath ~/.ssh/muxmasters/%C
Create folder if doesn't exist.
$ mkdir -p ~/.ssh/muxmasters
$ ssh 192.168.111.159 -- hostname user@192.168.111.159's password: remotehost
$ ls ~/.ssh/muxmasters 598a7155ff90f076057fb265730c6ffe5997d4bb
If multiplexing is active, you'll see the socket file listed.
$ ssh 192.168.111.159 -- hostname host
These sessions will use the master connection without the need for re-authenticating. It should also be very fast as long as you log in within the controlpersist period.
Comment anonymously. Login not required.