Set Up a VNC Linux Server in 5 Easy Steps
Author : Juliet Kemp - March 1st, 2010 - link to original article
Network Computing (VNC) allows you to log into a full desktop on a remote server (as opposed to just opening windows on your local machine, as with X11 over SSH). It can be very useful, and it's very fast to set up.
I chose to use vnc4 (there are other options, such as TightVNC), so the first step was the vnc4server Debian/Ubuntu package on my remote server. Once vnc4 is installed, run it for the first time to finish setup, and set a VNC password:
This starts a daemon off, rather than vnc4 running in the foreground. You'll get your shell prompt back once it's running.
To kill the server again, use
vncserver -kill :1
You will probably want to edit the ~/.vnc/xstartup file to control which applications and window manager are kicked off at startup. The default window manager is x-window-manager. I prefer Xfce4, which is lightweight and therefore good for running remotely. You can also use Gnome.
To specify, comment out the x-window-manager line and add a line for your preferred session:
Finally, it's better to run the session through an SSH tunnel (rather than unencrypted on port 5901, as by default). Run this command on the client machine:
ssh -f -N -L 5901:localhost:5901 email@example.com
Then start your server on the remote machine:
Finally, use a VNC client (e.g. xvnc4viewer for Linux, or Chicken of the VNC for Mac) to connect to localhost on port 5901 (the SSH connection is set to forward local port 5901 to remote port 5901), using your VNC password. And you're in! Just remember to kill the VNC server and your ssh process once you're done.