Server Fault is a question and answer site for system and network administrators. 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 am tunneling an nc connection to my target host ( over an ssh connection to my gateway. Below is my .ssh/config setup for this connection:

Host target
HostKeyAlias target
ProxyCommand ssh me@gateway /bin/nc 22

This is great and allows me to ssh to the target host in one step. What I would like to do is be able to tunnel an NX or VNC session over this connection.

Anyone know how this might be done?

share|improve this question
up vote 1 down vote accepted

I think you should use port forwarding that SSH already can do:

ssh -L me@gateway

This will forward port 5900 from your local machine to through gateway. Now just "vncviewer localhost" from your local machine.

share|improve this answer
much easier than my solution! – johnny_bgoode Sep 11 '10 at 23:41

Here's how a VNC session can be created over an ssh tunnel with a gateway hop in between the client and target machines:

/etc/ssh/sshd_config (on target machine) must have these lines:

X11Forwarding yes
XAuthLocation /usr/bin/xauth

Your path to xauth may be different, but by default sshd looks in the wrong location so this value should be set.

.ssh/config (on the client machine):

ProxyCommand ssh -t -C /bin/nc %h 22

Then from the client I can run

me@localhost$ ssh -X -C
This starts an X session on my client as well as an ssh connection to Now, just a couple more commands on the remote host to bring up VNC:$ vncserver :n$ vncviewer -encodings "copyrect tight zlib corre rre raw" :n

In the above commands, :n is is the display number where you want to start vnc and the display where vncviewer should look for the vnc session. Since this looks like a local connection to VNC it is a good idea to specify some better encodings as vncviewer will default to raw, giving poor performance over the network.

That's it!

share|improve this answer… – johnny_bgoode Sep 12 '10 at 2:21

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.