VNC Tutorial

What Is It?

VNC is free network application which allows you to use a computer from a remote location. Suppose you are, for instance, at a Microsoft Windows PC in location X, and wish to use a Linux box at location Y, with the Linux machine having network address a.b.c. Using VNC, you can get the same access to the Linux machine from the Windows PC that you would if you were sitting there at Y. You would see the same KDE display (or whatever) etc.

I will assume here the setting described above--Linux server, Windows client. Actually VNC is much more general than this. I will also assume you are running the browser-based client, though I'll say a bit on a different client, vncviewer, later.

Do You Already Have It?

Note first: If the machine on which you wish to run VNC ("Y" above) is running Linux, it may already have VNC installed. Type something like

which vncserver

to check for this. If the package is already installed, then you may of course skip the next two sections of this tutorial.

Where to Get It:

Download the software from the above address. Again, since I am assuming a Linux server, I will assume you download Linux binaries.

How to Install It:

The main items to store are the executables, especially the Perl script vncserver and the binary Xvnc, and the Java classes for the client. The latter are in the directory classes in the downloaded package.

As an example, let's supppose you choose to set up a subdirectory named vnc in your home directory, with further subdirectories vnc/bin and vnc/classes, adding the former to your search path. Copy the executables (vncserver etc.) to vnc/bin and copy classes/* to vnc/classes.

You'll need to edit the line in vncserver which sets the variable $vncClasses so that that variable is set to $HOME/vnc/classes. For example, when I did this, I changed the line to

$vncClasses = ((-d "/home/matloff/VNC/classes") && "/home/matloff/VNC/classes");

Again, make sure to add vnc/bin to your shell's search path.

How to Run the Server:

On the Linux box, type

vncserver :n

where n is a session number of your choice (it will be 1 if you do not specify it). The first time you do this, you will be asked to set up a password (which you can later change by running vncpasswd).

As above, suppose for example here that the Linux box has network address a.b.c. The server will start running on port m of a.b.c, where m = n + 5800. You can always check this in the file $HOME/.vnc/a.b.c:n.log after you've launched the server. If this port is already taken, VNC will tell you so, in which case you simply try again with another port. You can check which ports are taken (by other VNC servers) by typing something like

ps ax | grep Xvnc

You may run out of colors. If so, re-run the server with the option -depth 16. You may need to experiment here.

How to Run the Client:

Then on the Windows machine, have the Web browser access http://a.b.c:m. You will be asked to enter the password, and then the browser should show the console screen for a.b.c! You are now in business.

Exiting the Client:

When you are done with your session at the client, simply click Disconnect at the top of the screen. Do not logout from a.b.c.

Exiting the Server:

You can exit the server by typing

vncserver -kill :n

The Non-Browser Client

Using the browser client is really convenient, but it does rely on Java, and some browsers/configurations will have problems with Java. An alternative is to run vncviewer on the client side. You run it like this:

vncviewer a.b.c:m

where now m = n + 5900; if the server is number 1, then type 5901 here. Note that you should NOT include "http:" in the URL.

Another viewer is vinagre, which for instance is bundled with Ubuntu. Use the same command-line format as vncviewer above.

Security Issues:

VNC enforces some measure of security in that its client encrypts your password before sending it out over the network to the server.

Your VNC session itself, though, will not be encrypted. If for example while working on a.b.c remotely, you connect from the latter site to a third site using a password, the latter password will not be encrypted, and could conceivably be captured by a bad guy. If you need extra protection, VNC can be used in conjunction with SSH; check the Web for details.

X11 Issues:

The default window manager is twm, which is launched by $HOME/.vnc/xstartup. Of course, you can edit that startup file to change to a different window manager. For example, to get KDE, use this for your file $HOME/.vnc/xstartup:

For Gnome, have this:

If you use the default, here are the basic operations of twm: Whenever a new window is created, the user must drag it at least a little, so as to change from the "ghost" outline. To move a window, drag its upper border. To resize it, drag its upper-right corner. To get autoraise on a given window, left-click in the desktop background (i.e. not in any window), then click on the desired window.