Stopping SSH multiplexing sessions avoids leaving stale control connections and sockets behind, which can consume local resources and cause confusing behavior when reconnecting to the same host. Tearing down the control master also resets any reused authentication state, which is useful when switching identities or testing connection changes.

With multiplexing enabled, SSH uses a single long-lived control master process and a local Unix-domain socket defined by the ControlPath setting. New sessions for the same host connect to that socket and reuse the existing TCP connection instead of creating a new one, which speeds up repeated logins and command executions.

Stopping multiplexing means sending a control message through the socket using the ssh -O interface rather than logging into the remote system. Ending the control master closes all multiplexed sessions that depend on it, so active interactive shells or file transfers terminate immediately; checking the target host and configuration before issuing the exit command prevents unintentional disruption.

Steps to stop multiplexing sessions in SSH:

  1. Open a terminal on the local machine that initiated the multiplexed connections.
    $ echo "$SHELL"
    /bin/bash
  2. Display the effective SSH configuration for the target host to confirm that ControlMaster and ControlPath are enabled.
    $ ssh -G user@remotehost | grep -Ei 'controlmaster|controlpath'
    controlmaster auto
    controlpath /tmp/ssh-%r@%h:%p

    The ssh -G option prints the resolved configuration after merging all ssh_config files, making it easier to see whether multiplexing is active for a specific host.

  3. Check whether a multiplexing control master is currently running for the host using the control check operation.
    $ ssh -O check user@remotehost
    Master running (pid=18427)

    If the response reports that the master is not running, no multiplexed control connection exists for that host and no further action is required.

  4. Stop the multiplexing control master and close all multiplexed sessions by sending the exit control command.
    $ ssh -O exit user@remotehost
    Exit request sent.

    Terminating the control master immediately closes all multiplexed channels that depend on it, which interrupts active shells, port forwards, and file transfers using the shared connection.

  5. Verify that the control socket associated with the master is removed from the filesystem.
    $ ls -l /tmp/ssh-*
    ls: cannot access '/tmp/ssh-*': No such file or directory

    If the path shown in ControlPath differs from /tmp, adjust the directory in the listing command to match the configured socket location.

  6. Confirm that no multiplexed control master remains by running the control check command again.
    $ ssh -O check user@remotehost
    Master is not running
Discuss the article:

Comment anonymously. Login not required.