Contributed by todd on from the when-you-just-want-an-example dept.
Back when OpenSSH 4.2 was released, the first item mentioned under bugfixes and improvements was about the ControlMaster=auto/autoask option having been added to support opportunistic multiplexing. Aside from being a mouthful, you might wonder what this means.
By adding this to my $HOME/.ssh/config file:
Host * ControlPath ~/.ssh/ctl-%r-%h-%p ControlMaster auto
.. I ssh to a machine named 'eclipse' in one xterm on my laptop:
todd@blue/p7 4126$ ssh eclipse todd@eclipse's password: Last login: Wed Sep 14 11:46:00 2005 from blue.isp.fries.net OpenBSD 3.8 (GENERIC) #130: Mon Aug 29 11:40:56 MDT 2005 todd@eclipse/p0 1$
So far, nothing is different. Or is it? Back on my laptop, I see this new file created:
todd@blue/p8 3966$ ls -l $HOME/.ssh/ctl-todd-eclipse-22 srw------- 1 todd todd 0 Sep 14 23:18 /u/todd/.ssh/ctl-todd-eclipse-22= todd@blue/p8 3967$
This is a 'socket' denoted by the 's' on the far left of the filename. With this, subsequent ssh connections to eclipse from my laptop will use the socket and utilize the existing connection instead of establishing a new one:
todd@blue/p8 3967$ ssh -v eclipse OpenSSH_4.1, OpenSSL 0.9.7g 11 Apr 2005 debug1: Reading configuration data /u/todd/.ssh/config debug1: Applying options for * debug1: Reading configuration data /etc/ssh/ssh_config debug1: auto-mux: Trying existing master Last login: Wed Sep 14 23:17:03 2005 from blue.wfi.fries.net OpenBSD 3.8 (GENERIC) #130: Mon Aug 29 11:40:56 MDT 2005 todd@eclipse/p1 1$
This has really saved me a lot of time since I started using this new functionality. If you are a regular user of ssh on a unix system, I suspect it will save you time as well!
Disclaimer: Only available via Protocol 2, limit of 10 connections per socket.
(Comments are closed)
By sat (66.65.113.58) on
Comments
By Todd T. Fries (208.54.30.236) todd@openbsd.org on http://todd.fries.net/
By Mark Garcia (71.39.45.177) mail to mag at wavecentral d0t com on
The features that were missing, that are addressed in this release are the macro expansion of %r, %h, %p. And the addition of 'auto' and 'autoask' for the ControlMaster argument. 'auto' puts the intelligence back into ssh to detect if an existing socket file exists, and then use it. Or if it doesn't, then create it inheriting noask (removing the pop-up ask option for allowing someone to use an already existing connection.)
Use 'autoask' and you get the same intelligence, but it flags it with an ask option on future connection to the same user/host/port.
-.mag
By djm@ (203.58.120.11) on
If you know that you are going to be using a server frequently, you can initiate a backgrounded master connection to it that will persist until you tell it to go away. Assuming you already have Todd's config bits in ~/.ssh/config, you can do:
ssh -Nnf user@yourhost
which will set up a master connection that puts itself in the background after authentication. All subsequent connections will automagically use it.
When you want it to go away, you can signal it using the multiplex "command mode" option:
ssh -O exit user@yourhost
Another useful -O command is "-O check", which will report on the master's PID. This might be useful in scripts that need to make sure a connection is alive (e.g. distcc).
There is more work planned for the multiplexing code, in particular the ability to add port forwardings to an active master and hooking up the channel escape (e.g. "~.") handler.
By Jim (68.250.26.213) on
This is awesome!