SSH Session Multiplexing

I have a new favorite ssh feature! Not that password-less public key authentication, port forwarding or X11 forwarding weren't really cool. But session multiplexing is really sweet.

Included in version 3.9, session multiplexing is a faster way to run multiple ssh session to a single remote host. When you login to a machine (call it 'remotehost') the first time, you tell that ssh session to become the "ControlMaster" (-M option).

# ssh -M -S ~/.ssh/remote-mux user@remotehost
Ssh will start a session as usual and also open up a Unix domain socket using the filename you provide in the ControlPath argument (-S option).

To start another ssh session to the same host, you can do:

# ssh -S ControlPath=~/.ssh/remote-mux user@remotehost
Ssh will skip authentication (as you've already auth'd to remotehost) and will use the existing TCP connection for the second connection. The upshot of this is that logging in a second (or third!) time is instantaneous.

Adding the -S and -M options on the command line is tedious. You can setup your .ssh/config file like this:

Host remotehost
   HostName remotehost
   User user
   ControlMaster yes
   ControlPath ~/.ssh/remote-mux

Host remotehostfast
   HostName remotehost
   User user
   ControlMaster no
   ControlPath ~/.ssh/remote-mux
For your first connection, do:
# ssh remotehost
For your subsequent connections, do:
# ssh remotehostfast

Link to story

Technorati tags for this post:

Comments on "SSH Session Multiplexing":

Comment by F Beckmann

Posted at May 13th 2005.
Hi :-) Nice Tip ! Thanks !!! Greetings from Germany Frank

Comment by ed@membled.com

Posted at Jul 31st 2005.
A shame you have to type a different command for the first and subsequent sessions. Apparently the current development version of openssh has 'ControlMaster auto' which does the right thing.

Comment by ed@membled.com

Posted at Jul 31st 2005.
Yes, here's how to set up transparent multiplexing with the current dev openssh. - Build and install a development snapshot from (or a mirror site if it's up to date). If you use Fedora Linux or a similar distribution you could try my source package (do 'rpmbuild --rebuild' on it). If you use OpenBSD then get the main OpenSSH release not the 'portable' one. - In your ssh config file, for example ~/.ssh/config, put Host * ControlMaster auto ControlPath ~/.ssh/remote-mux-%r@%h:%p You could restrict this to just one host instead of '*'. It appears to Just Work(tm); the first session becomes the master and stays open until all child sessions have closed. As noted in the docs, there are some side effects with X forwarding and port forwarding.

Comment by ed@membled.com

Posted at Jul 31st 2005.
Argh, moronic blog software doesn't escape correctly less-than or greater-than characters. I was referring to the URIs ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/snapshot/ and http://membled.com/work/RPM/SRPMS/openssh-20050713-1.src.rpm.

Comment by matt

Posted at Jul 31st 2005.
"ControlMaster auto" -- very nice! Thanks!

Comment by rene

Posted at Feb 9th 2006.

The example given is wrong.
Instead use: ssh -S ~/.ssh/remote-mux user@remotehost
Allowed html tags: br p blockquote i b em code strong u ol ul li a
(type "HuMaN" here)