How to use OpenSSH Multiplexer To Speed Up OpenSSH Connections on Linux

This article will help us to understand the multiplex SSH sessions by setting up a master session, then having subsequent sessions by using multiplexer to speed up the SSH connection on Linux.


Multiplexing is nothing but send more than or more over a single connection of SSH and can reuse the existing TCP/IP connection for multiple concurrent SSH connection. This will reduce the load of creating new TCP connections on the server.

Advantages of Multiplexer on SSH Connection.

  • It uses the existing *inx socket to connect.
  • IT uses existing TCP/IP connection no more new TCP/IP.
  • No more key exchanges.
  • No need of authentications.

Configuring Multiplexing

If the config does not exist in the .ssh folder in your home directory, create it with permissions 600: readable and writable only for you.

Edit the .ssh/config of the user –

# vi ~/.ssh/config
ControlMaster auto
   ControlPath ~/.ssh/master-%r@%h:%p.socket
   ControlPersist 30m

Sample Config file –

Host *
   ControlPath ~/.ssh/master-%r@%h:%p
   ControlMaster auto
   ControlPersist 30m


Host * or Host client : This start SSH configuration.
ControlPath ~/.ssh/ssh-mux-%r@%h:%p : This specifies the path to the control *inx socket to be used for connection and sharing is as described in the above.
The variables
‘%r’ - remote ssh username
‘%h’ - remote ssh host
‘%p’ - remote ssh port
You need to set all of these three variables for this option.

ControlMaster auto: This enables the sharing of multiple sessions over a single network connection. When this set to yes, the SSH will listen for connections on a control socket specified using the ControlPath argument.
When this set to auto, ssh will try to use a master connection, but the connection falls back to creating a new one connection, if one does not exist.
ControlPersist 30m: This option specifies that the master connection should remain open in the background for 30 minutes.
If the connection is with no clients, then the backgrounded master connection will automatically terminate after it had remained idle for 30 minutes.

How to Connect

From a client machine connect to the server with below commands.

#ssh root@
The authenticity of host ' (' can't be established.
RSA key fingerprint is f7:c8:62:c9:6f:02:50:8e:14:cd:3a:95:ad:b1:67:af.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (RSA) to the list of known hosts.
root@'s password:
Last login: Fri Apr 22 13:26:56 2016 from

How to Verify Multiplexer is Working or Not?

Go to the SSH server and run the below command.

# lsof -U | grep master
ssh       69518       root       4u       unix0xffff8801378f7580    0t0 607468 /root/.ssh/master-root@
ssh       69518       root       5u       unix0xffff880139986b80    0t0 607482 /root/.ssh/master root@


We can check with another command

# ssh -O stop
Master running (pid=69518)

If we run a lot of terminal or scripts using OpenSSH connections to the same server, you can speed them by using the multiplexing, which makes first connection as the master and allowing the others connected to share its TCP connection to the server.

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 20-Jan-2020


Kickstart Your Career

Get certified by completing the course

Get Started