Skip to content

How to Use SSH Multiplexing and Control Commands

Updated 2 min read

Updated: 22 October 2026 · Applies to: OpenSSH client

If you regularly connect to the same server for remote logins, administration or automated tasks, SSH multiplexing reuses one existing connection instead of negotiating a new one every time, which noticeably speeds up repeated connections. Knowing the control commands also helps when a multiplexed session hangs, for example after an IP change, a VPN reconnect, or a firewall interruption.

Set up multiplexing

Create a folder to hold control sockets:

mkdir -p ~/.ssh/controlmasters/

Start a master connection:

ssh -M -S ~/.ssh/controlmasters/server-socket username@hostname
  • -M: enables master mode.
  • -S: path for the control socket, created automatically.
  • username@hostname: your SSH username and the server's address.

If the server uses a non-default SSH port:

ssh -p PORT_NUMBER -M -S ~/.ssh/controlmasters/server-socket username@hostname

After that, connect normally, without -M or -S:

ssh username@hostname

Set it up automatically with SSH config

Instead of typing the socket path every time, add this to ~/.ssh/config:

Host myserver
    HostName SERVER_ADDRESS
    User USERNAME
    Port 22
    ControlPath ~/.ssh/controlmasters/%r@%h:%p
    ControlMaster auto
    ControlPersist yes

Then just connect with:

ssh myserver

Or apply it to every host at once:

Host *
    ControlPath ~/.ssh/controlmasters/%r@%h:%p
    ControlMaster auto
    ControlPersist yes

Manage an existing multiplexed connection

Once a master connection exists, control it with ssh -O:

Check whether the master is running:

ssh -O check username@hostname

Close it safely, letting existing sessions finish:

ssh -O stop username@hostname

Close it immediately, ending every session on it:

ssh -O exit username@hostname

Prefer stop over exit unless you specifically need to end active sessions right away.

Forward a port over the multiplexed connection

ssh -O forward -L LOCAL_PORT:REMOTE_HOST:REMOTE_PORT username@hostname

Cancel it again:

ssh -O cancel username@hostname

For example, to forward a web service on the remote side:

ssh -O forward -L 8443:10.0.0.1:8443 username@hostname

See the speed difference for yourself

With multiplexing (after a master connection is already open):

time ssh username@hostname true

Without it:

time ssh -o 'ControlMaster=no' -o 'ControlPath=no' username@hostname true

Compare the two times; the multiplexed connection should be noticeably faster since it skips the full handshake and authentication.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket