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:

  1. Launch the terminal on your local machine.
  2. Open the SSH client configuration file using your preferred text editor.
    $ vi ~/.ssh/config
  3. Specify the host(s) where you want to enable multiplexing.
    Host *

    * applies to all hosts. You can specify individual hosts or use patterns.

  4. Enable multiplexing for the selected host(s).
    Host *
        ControlMaster auto
  5. Set the duration for how long the multiplexing session should persist.
    Host *
        ControlMaster auto
        ControlPersist 10m
  6. 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
  7. Establish the master connection by connecting to your server.
    $ ssh user@remotehost
  8. 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.

  9. 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.

Discuss the article:

Comment anonymously. Login not required.