Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

There are plenty of "recipes" out there that suggest using Netcat for ProxyCommand with the ssh program (either on the command line or in the ~/.ssh/config file).

The entry in the configuration file usually looks as follows:

Host internal
  HostName internal
  ProxyCommand ssh gateway nc -w 10 %h %p 2> /dev/null

The -w 10 being a timeout given to Netcat so that no stale instances of nc remain once the SSH connection ends.

How can I achieve the same using ssh's -L or a similar method, i.e. using the SSH client itself as the proxy command?

The following allows me to tunnel the connection to the host internal to the local port 2222:

ssh -f -q -L 2222:internal:22 gateway sleep 10

... but how can I make this completely transparent for use in ProxyCommand so as not to have to rely on nc being installed? (above command obviously expects that someone make use of the tunnel on port 2222 within those 10 seconds specified in the sleep command).

Note: in particular this has to be usable for unprivileged users as well.


Also note: my ssh command doesn't support -W, which apparently could act as one of the possible alternatives here.

share|improve this question
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.