Super User is a question and answer site for computer enthusiasts and power users. 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 wanna connect to a group of machines using a specific machine using ssh tunneling. But in all solutions found, I need to specify a entry per machine in my ssh config file. I would like to use a wildcard in this way:

   Host *
   // some magic here

For now, the best solution found was:

share|improve this question
Does the tunnel server allow executing commands (specifically netcat, nc and/or socat), or is it strictly tunneling-only? – grawity May 7 '12 at 18:19
yes! it can execute commands! – Jonhnny Weslley May 7 '12 at 18:21
up vote 1 down vote accepted

If you can run programs such as nc or netcat or socat on your tunnel server, you could use a ProxyCommand instead of a port forward:

# Only necessary if it matches the * wildcard. Useless otherwise.
    ProxyCommand none

Host *
    ProxyCommand ssh nc %h %p
    #ProxyCommand ssh ncat %h %p
    #ProxyCommand ssh socat stdio tcp:%h:%p
    #ProxyCommand ssh netcat %h %p

Uncomment the apropriate ProxyCommand, depending on what tools the tunnel server has installed.

Note that this will set up and tear down a separate SSH connection for every tunnel established, which means connecting will be slower than via SOCKS. (It won't affect performance after connection, however.)

If your SSH version supports it, you could enable connection multiplexing:

    ControlMaster no
    ControlPath none

Host *
    ControlMaster auto
    ControlPath ~/.ssh/S.%l.%r@%h:%p
    ControlPersist 10m
share|improve this answer
thanks @grawity! SOCKS rocks! – Jonhnny Weslley May 7 '12 at 18:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .