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.
Related: How to use multiplexing in SSH
Related: How to check SSH multiplexing session status
Related: How to improve SSH performance and speed
$ echo "$SHELL" /bin/zsh
$ ssh -G host-mux | grep -Ei 'controlmaster|controlpath' controlmaster auto controlpath /home/user/.ssh/muxmasters/79b54c680bc3a687c54a4b2e86e6605d44c58129
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.
$ ssh -G host-mux | awk '/^controlpath /{print $2}'
/home/user/.ssh/muxmasters/79b54c680bc3a687c54a4b2e86e6605d44c58129
Use the resolved socket path with ssh -S when you need to target a specific master:
$ ssh -S /home/user/.ssh/muxmasters/79b54c680bc3a687c54a4b2e86e6605d44c58129 -O check host-mux
To make socket names readable, use a ControlPath pattern like
~/.ssh/muxmasters/%r@%h:%p
instead of the hashed
%C
.
$ ssh -O check host-mux Master running (pid=14924)
If the response reports that the master is not running, no multiplexed control connection exists for that host and no further action is required.
$ ssh -O exit host-mux 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.
$ ls -l ~/.ssh/muxmasters total 0
If the path shown in ControlPath differs from ~/.ssh/muxmasters, adjust the directory in the listing command to match the configured socket location.
$ ssh -O check host-mux Control socket connect(/home/user/.ssh/muxmasters/79b54c680bc3a687c54a4b2e86e6605d44c58129): No such file or directory