Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I see from the ssh_config man page that you can share connections to host@user using ControlPath and ControlMaster.
Is there any way to do this opportunistically for each combination of local user, remote user, and remote host? So that the first connection to testuser@remotelaptop is shared when you ssh into it the second time and the first is still running?

(I use ssh keys. I'm not sure if that would make it easier or harder).

share|improve this question
up vote 6 down vote accepted

From the ssh_config man page:

    Two additional options allow for opportunistic multiplexing: try
    to use a master connection but fall back to creating a new one if
    one does not already exist.  These options are: “auto” and
    “autoask”.  The latter requires confirmation like the “ask”

So if you configure ssh with ControlMaster auto, it will attempt to connect to use an existing SSH session, falling back to creating a new master connection if that fails.

So a configuration like the following is probably what you're after:

ControlMaster auto
ControlPath ~/.ssh/control/%r@%h:%p
share|improve this answer
Nice! Now why didn't I scroll down just a little bit in my terminal and see that part of the man page? :) – Azendale Sep 19 '11 at 20:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.