2

I am tunneling an nc connection to my target host (example.com) over an ssh connection to my gateway. Below is my .ssh/config setup for this connection:

Host target Hostname example.com HostKeyAlias target ProxyCommand ssh me@gateway /bin/nc example.com 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?

2 Answers 2

2

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

ssh -L 5900:example.com:5900 me@gateway 

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

1
  • much easier than my solution! Commented Sep 11, 2010 at 23:41
2

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):

Host example.com Hostname foo.example.com HostKeyAlias example.com ProxyCommand ssh -t -C [email protected] /bin/nc %h 22 

Then from the client I can run

me@localhost$ ssh -X -C example.com
This starts an X session on my client as well as an ssh connection to example.com. Now, just a couple more commands on the remote host to bring up VNC:

[email protected]$ vncserver :n [email protected]$ 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!

1

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.