Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to use OpenSSH Multiplexer To Speed Up OpenSSH Connections on Linux
This article will help you understand how to multiplex SSH sessions by setting up a master session and using a multiplexer to speed up SSH connections on Linux.
What is SSH Multiplexing?
SSH Multiplexing allows multiple SSH sessions to share a single TCP/IP connection. Instead of establishing separate connections for each SSH session, subsequent connections reuse the existing master connection, reducing server load and improving connection speed.
Advantages of SSH Multiplexing
-
Reuses existing connections − Uses the established Unix socket to connect.
-
No additional TCP overhead − Eliminates the need for new TCP/IP connections.
-
Skips key exchanges − Subsequent connections bypass cryptographic handshakes.
-
No re-authentication − Authentication is handled by the master connection.
Configuring SSH Multiplexing
Create or edit the SSH configuration file in your home directory. If ~/.ssh/config doesn't exist, create it with permissions 600:
chmod 600 ~/.ssh/config
Add the following configuration to ~/.ssh/config:
Host *
ControlPath ~/.ssh/master-%r@%h:%p.socket
ControlMaster auto
ControlPersist 30m
Configuration Options Explained
-
Host * − Applies configuration to all SSH connections.
-
ControlPath − Specifies the path to the control Unix socket. Variables:
%r(remote username),%h(remote host),%p(remote port). -
ControlMaster auto − Automatically creates a master connection or reuses existing ones.
-
ControlPersist 30m − Keeps the master connection open for 30 minutes after the last session closes.
Testing SSH Multiplexing
Making a Connection
Connect to your server as usual. The first connection becomes the master:
$ ssh root@192.168.2.225 The authenticity of host '192.168.2.225 (192.168.2.225)' 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 '192.168.2.225' (RSA) to the list of known hosts. root@192.168.2.225's password: Last login: Fri Apr 22 13:26:56 2016 from 192.168.1.84
Verifying Multiplexing is Active
Check for active master connections using lsof:
# lsof -U | grep master ssh 69518 root 4u unix0xffff8801378f7580 0t0 607468 /root/.ssh/master-root@192.168.2.225.socket
Alternatively, check the master connection status:
$ ssh -O check 192.168.2.225 Master running (pid=69518)
Managing Master Connections
You can control master connections using SSH's -O option:
# Stop the master connection ssh -O stop 192.168.2.225 # Exit the master connection ssh -O exit 192.168.2.225
Conclusion
SSH multiplexing significantly improves connection speed by sharing a single TCP connection among multiple SSH sessions. This is especially beneficial when running multiple terminals or scripts that frequently connect to the same server, reducing authentication overhead and network latency.
