SSH (Secure Shell) is a tool for secure remote access and file transfer. One of its advanced features is multiplexing, which allows multiple SSH sessions to share a single network connection. This reduces connection overhead and speeds up operations.
Using multiplexing is beneficial when you need to run multiple commands on a remote server. Instead of creating a new connection each time, you can reuse an existing connection. This makes tasks faster and more efficient, especially in automated scripts where multiple commands are executed in succession.
Multiplexing is configured through the ControlMaster, ControlPath, and ControlPersist options in the SSH client configuration. These settings enable you to manage master and client sessions effectively.
Steps to use multiplexing in SSH:
- Launch the terminal on your local machine.
- Open the SSH client configuration file using your preferred text editor.
$ vi ~/.ssh/config
- Specify the host(s) where you want to enable multiplexing.
Host *
* applies to all hosts. You can specify individual hosts or use patterns.
- Enable multiplexing for the selected host(s).
Host * ControlMaster auto
- Set the duration for how long the multiplexing session should persist.
Host * ControlMaster auto ControlPersist 10m
- Define the path and filename for the ControlMaster socket file.
Host * ControlMaster auto ControlPersist 10m ControlPath ~/.ssh/muxmasters/%C
Create the folder if it doesn't exist.
$ mkdir -p ~/.ssh/muxmasters
- Establish the master connection by connecting to your server.
$ ssh user@remotehost
- Verify that multiplexing is active by checking the existence of the socket file specified in ControlPath.
$ ls ~/.ssh/muxmasters
If multiplexing is active, the socket file will be listed.
- Open new SSH sessions to the same host while the master connection is active.
$ ssh user@remotehost
These sessions will use the master connection, making them faster and requiring no re-authentication.
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.