== How I use ssh's connection sharing feature Following on [[the basic overview SshConnectionSharing]], here's how I use OpenSSH's connection sharing feature. First, since I hate programs that don't exit when I want them to, I don't let _ssh_ automatically create connection masters. Instead I always explicitly create them myself, so that I can do so in a way that harmlessly parks them in the background. So while I set a _ControlPath_ (to a value mentioned in the [[previous entry SshConnectionSharing]]), I leave _ControlMaster_ set to _no_, the default. When I want to create a master _ssh_, I have a script that boils down to: > _ssh -M -f -o "BatchMode yes" $HOST exec sleep 120_ You might wonder about the '_sleep 120_'. One of the peculiarities of how I use connection sharing is that so far I always do it to hosts that I also have persistent sessions to. These persistent sessions pin the master _ssh_ in place whether or not the master _ssh_ itself is still doing anything, so the _sleep_ does two things here. First, it keeps the master _ssh_ going long enough for my real sessions to start, and second, it means that if and when I later tear down all of my real sessions to the host, the master _ssh_ will also exit because the _sleep_ has long since finished. (Ideally there would be a _ssh_ option for 'keep running N seconds after the last session closes to see if a new subordinate shows up'. Then I could set that to 120 seconds or so and just use '_/bin/true_' as the command that the master _ssh_ runs.) In actual practice I don't create master _ssh_ instances by hand. Instead I do it from my X startup file, which (vastly simplified) winds up looking like: > ssh-master host1 > sleep 1 # give it time to come up > ssh host1 x-app-1 & > ssh host1 x-app-2 & > .... (And then anything else that I want to do on host1 later will also get the benefits of using the existing connection.) Among other things, this approach has the benefit that it's easy to add. I didn't need to change anything that my X startup script was already doing; I just inserted an additional command early on. (And then took it out again the first time I tried it, when it turned out to cause various problems.)