OnlineWebTools

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.

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:

  1. Launch terminal.
  2. Open SSH client configuration file for your user using your preferred text editor.
    $ vi ~/.ssh/config
  3. 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.*
  4. Enable multiplexing for the selected host(s).
    host *     controlmaster auto

  5. Set how long do you want the multiplexing session to persist.
    host *     controlmaster auto     controlpersist 10m
  6. 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
  7. Check for existing control file on local host.
    $ ls ~/.ssh/muxmasters
  8. Log in to a remote host.
    $ ssh 192.168.111.159 -- hostname user@192.168.111.159's password:  remotehost
  9. Check for created control file to confirm.
    $ ls ~/.ssh/muxmasters 598a7155ff90f076057fb265730c6ffe5997d4bb
  10. 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.

Exit mobile version