Wednesday, October 17, 2007

VNC over SSH with Ubuntu (or any other OS)

Virtual Network Computing (VNC) allows a user to access his or her desktop from a remote location. It is somewhat analogous to Remote Desktop Computing, available on Windows XP Pro, except that Remote Desktop uses Remote Desktop Protocol (RDP), an encrypted form of information exchange whereas VNC is not encrypted. VNC requires a server on the host machine, ie the desktop being controlled, and client software that is used to access the server. With Ubuntu, the server exists by default. To activate it, go to System->Preferences->Remote Desktop and choose Allow others to view your desktop and Allow others to control your desktop. Since you are going to be at a different location deselect Ask for your confirmation and then select a password to use and close.



To access this VNC server I use TightVNC. Just download the windows viewer, which is a portable executable, i.e. you can take the vncviewer.exe program and put it on a USB drive and it will run from there, or anywhere else independent of your privileges.

The default port to access your desktop is 5900. For information port forwarding and networking with virtual machines, check out my previous blog. It is my understanding that you cannot change the default port used by vino - Ubuntu's default vnc server.

To use VNC: from another computer running windows double click the vncviewer.exe. You can leave the defaults as they are; however, I like to change the default little cursor to an arrow. To do this click on options, then click on the globals tab then under Local cursor shape choose Normal arrow and then OK.



Now it is time to connect to your Ubuntu desktop! NOTE: This is for testing purposes only. VNC is not a secure method of communication, meaning there is no encryption of the data passing from the remote client to the host. Therefore any information passed between the two, such as passwords, could be easily available to some outside interception. This is the reason for using the SSH tunnel to be described next. To connect to your Ubuntu desktop enter it's IP address in the blank field, followed by a colon and then the chosen port. For information about how to find your IP address check out this blog. If you are within the same network as your Ubuntu machine then use the network address, otherwise use the outside address.



You should be presented with a screen asking you for your password, after which you should see your nice shiny remote desktop presented on your screen! The quality of the experience depends heavily on the speed of the connection. With a good network connection I can hardly tell the difference when I'm on my laptop remote computing to my desktop. Now close the vncviewer.

Now to make it secure. I describe setting up Openssh server on Ubuntu here. In order to access the server you need an SSH client. I prefer PortaPutty. This along with tightvnc make a nice little portable package. Open up portaputty and type in your Ubuntu's IP address and port, as well as a name for the session under Saved sessions.



In the left column expand the Connection tab, click on Data, and in the Auto-login username field enter the username you use to login to your Ubuntu OS.



Now expand the SSH tab and click on tunnels. In source port enter the port for your vnc server. In the Destination field enter the IP Address of the server, a colon, and the port of the vnc server then click Add. Make sure the local button is filled. The result should look like this:



Now go back to the Sessions screen and click on Save to save all of these settings with the name you chose. To activate this session just double click the saved name and you will be presented with a command line looking box. Your username will be presented and then you will be asked for your password:



Finally you will be presented with a command prompt. Now you have established a secure, encrypted SSH tunnel through which to pass the VNC session. With the SSH session open, activate vncviewer.exe, but instead of your computer's IP address enter 'localhost', colon, and the port through which you are tunneling.



You should be presented with the same password request as earlier and then your remote desktop. Now you are Virtually Computing securely via an encrypted SSH tunnel!

No comments: