HowTo: Tunneling VNC Connections Over SSH

by Vivek Gite on May 8, 2006 · 8 comments

Virtual Network Computing (VNC) is a desktop sharing system which uses the RFB (Remote FrameBuffer) protocol to remotely control another computer. It transmits the keyboard presses and mouse clicks from one computer to another relaying the screen updates back in the other direction, over a network.

Step by step procedure

You can easily tunnel VNC connections over ssh so that entire traffic get encrypted. Type the following command to tunnel VNC connections over SSH (you need to type command on your desktop computer running UNIX or Linux):
$ ssh -L 5901:localhost:5901 -N -f -l rocky sshserver.mydomain.com
OR
$ ssh -L 5901:127.0.0.1:5901 -N -f -l rocky 192.168.1.100

Where,

  • -L 5901:localhost:5901 : Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side. Here you are using port 5901 on the localhost to be forward to sshserver.mydomain.com on the 5901 port.
  • -N : Do not execute a remote command i.e. just forward ports.
  • -f : Requests ssh to go to background just before command execution. Requests ssh to go to background just before command execution. Once password supplied it will go to background and you can use prompt for type commands on local system.
  • -l rocky : rocky is the user to log in as on the remote machine (sshserver.mydomain.com).
  • sshserver.mydomain.com (192.168.1.100): Remote system with VNC server

In your localhost VNC client use 127.0.0.1:5901 for connection. Make sure you use appropriate port i.e. 5901 (VNC server running on display 1). This tunnel will provide nice enhanced security.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 8 comments… read them below or add one }

1 weyasey February 2, 2009

Great tutorial, it was clear and the explanation of the switches made it all understandable.
Thanks very much it helped me a great deal.

Reply

2 Anonymous April 17, 2010

Thank you, very good and clear. Indeed simpler than that from vnc client on windows

Reply

3 TT January 30, 2011

Do you know if I need the SSH protocol over a network and behind a firewall in Window platform using tight VNC?

Reply

4 baba February 8, 2011

great reference on a great site! however, following the scenario i am prompted with a password in my vnc client (vinagre) and none of the ones i provide work. any ideas?

Reply

5 baba February 8, 2011

sorry, my bad, it was the vnc password

Reply

6 YBR February 11, 2011

Thanks for this Ho-To. One additional note – you don’t have to specify “localhost” in the ssh -L command….I used this to tunnel from work into my home Linux box, and pointed it at the VNC server running on a laptop on my home network. Now I can nannycam! Here is what I did: ssh -L 5600:10.248.26.18:5900 plony@plony.com
(note, IP numbers/names have been changed to keep honest people honest :-)

Reply

7 Allen May 26, 2011

Is there a way to force all users to tunnel to use vnc?

Reply

8 Dhairya August 9, 2011

I followed these steps and could easily connect to remote machine. But now the problem is my localhost is not working as nginx server is unable to listen to 127.0.0.1. any solution?

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 13 + 6 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: