Multiplexing allows a single connection to be shared by multiple SSH sessions. The connection could also be set to persist for a set time and reused for fast re-connection.

Sharing of multiple sessions for SSH 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
    [email protected]'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 logged in again within the controlpersist time value.

Discuss the article:

Comment anonymously. Login not required.

Share!