Tuesday, August 07, 2007

VNC Server on Kubuntu (Real Console Display) with SSH Tunneling

Ok, so I've set this up many times and each time it seems to be a pain so I finally figured out a smooth method and am writing it up.

First off, you get x11vnc and vnc-common

apt-get install x11vnc vnc-common

Now, it used to be you'd have to mess with MIT-Cookies and all sorts of insanity, but now, I found a better way. You will need to edit your desktop manager setup:

GNOME /etc/X11/gdm/Init/Default (or Init/:0)
KDE /etc/kde*/kdm/Xsetup

Add the following line:

x11vnc -bg -o /var/log/x11vnc.log

Now this is assuming that x11vnc is in your path, which if you install via apt-get it will be. Now, the -forever makes it persistent so it won't die when you disconnect, and -bg is just background...

The -rfbauth is important as this is your authentication.

We will create the password for this by running (need to do this as root (sudo -i)) vncpasswd and entering a password.

Now we need to create the .x11vncrc file in the root home dir so you don't have to put a big string in the above line... Add the following in the file:

display :0 # This will let you connect to the primary display
rfbauth /root/.vnc/passwd # password file - critical for auth
rfbport 5900 # port to listen on
forever # Without this x11vnc will die after serving one connection.
localhost # Only accept local connections. This makes your x11vnc secure along with SSH.
solid darkblue # Optional (changes background into solid color)
rfbversion 3.6 #This and the line below are only if you are wanting to use the file transfer function in UltraVNC.
permitfiletransfer

The most important thing in this file is the localhost line so we don't open up tcp/5900 external to the box. We will be tunneling to it via SSH and Putty.

Now you are pretty much ready to rock and roll. You can restart kdm and it should start x11vnc.

Now easy access from windows, just run Putty, setup your SSH connection as usual, but then go into the advanced config and set the 5900 tunnel as shown:



Now just SSH in with Putty, login as normal and then fire up your favorite vnc client and connect to localhost.

You should be rocking and rolling...

Enjoy.