Unix Power ToolsUnix Power ToolsSearch this book

47.7. Sharing Desktops with VNC

Figure Go to http://examples.oreilly.com/upt3 for more information on: VNC

Virtual Network Computing (VNC) is an open source project from AT&T Labs in Cambridge, England. It is a client/server system that allows users to manipulate desktop environments remotely. There are VNC servers for Unix, Windows, and pre-MacOS X environments. The options for clients are even wider since there is a Java applet VNC client. This can be used on any system that supports a modern web browser and Java. There is also a native VNC client for Unix, Windows, and pre-MacOS X machines. VNC provides a platform-independent way to control a heterogeneous network from any client platform.

VNC provides a live picture of a desktop. When you move your mouse on the client end, the mouse also moves on the server. The VNC client gets a kind of "graphic diff" of the change on the remote desktop and applies that to its current notion of the desktop. As you might guess, VNC isn't ideal for high-performance video games, but it is very serviceable for system administration and development.

You can get either precompiled binaries or the source code at http://www.uk.research.att.com/vnc/download.html. If you choose to compile VNC from the source, you will need to get and unpack the tar archive from the above site. To build the source, change into the unpacked archive directory and type:

$ xmkmf
$ make World && cd Xvnc && make World

If the compile goes cleanly, change to root and install:

# make install

47.7.1. Connecting to a Windows VNC server

Setting up a VNC server on a Windows machine is fairly straightforward. Simply grab the appropriate binary from the VNC download page, unzip the archive, and run the SETUP.EXE program in the vncserver folder. VNC will create a folder in the Start menu in which you'll find the VNC server program. When started, this program will ask you for a password that clients will need to be able to use your Windows machine.

Connecting to any VNC server requires three things. The first is the server's hostname or IP address. The second is the display number of the remote desktop. Windows and Macintosh servers can only have one display (the desktop), while Unix machines can have many VNC servers active at once (just like they can have many X sessions running concurrently). Display numbers begin at zero. The last piece of information needed is the password. Be advised that this password is in no way secure, nor is the VNC network traffic encrypted.

To connect to a VNC server requires running X. From an Xterm, type the following:

$ vncviewer hostname:display_number

If the VNC server is running on that machine, you'll be prompted for a password. You should see something like Figure 47-2.

Figure 47-2

Figure 47-2. Unix VNC client connecting to a Windows server

VNC desktops are also available through Java applets that can be accessed through modern web browsers. The URL for that applet is comprised of the hostname of the VNC server and a port number that is the display number plus 5800. For example, the URL for connecting to the VNC server on a Windows machine called karl.oreilly.com would be http://karl.oreilly.com:5800.

47.7.2. Setting up VNC on Unix

It is sometimes convenient to be able to connect to a Unix desktop remotely from a machine that isn't running X. Fortunately, setting up VNC on UNIX can be as straightforward as:

$ vncserver

VNC will pick the next available display number for your VNC server and report this to you.

New 'X' desktop is marian:1

Starting applications specified in /home/jjohn/.vnc/xstartup
Log file is /home/jjohn/.vnc/marian:1.log

If you haven't picked one before, you will be prompted for a password. Again, this has nothing to do with your system's /etc/passwd. Keep in mind that the new server is running under the account that started it. The security issues are manifold, so think carefully about how you deploy this very useful service.

By default, VNC runs the very lean window manager twm. The fewer the needless graphic elements, the better network performance you can expected. However, you can adjust the details of that desktop by looking in your home directory for the .vnc directory. There, you'll find the VNC log, pid, and password files. More importantly, you'll find the xstartup file, which works just like xinitrc. You can start X programs, set the desktop color, and choose the window manager to run from this file. Here's an example of the kinds of customizations you can do:

#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid gray85 &
xterm -fg blue    -bg lightyellow -g 80x25+0+0 &
xterm -fg red     -bg lightyellow -g 80x25+0-0 &
xterm -fg darkgreen  -bg lightyellow -g 80x25-0+0 &
xclock -digital -update 5 -bg lightyellow -g -0-300 &
exec twm

Here, three Xterms and xclock are arranged in a convenient way. VNC will also look in your .twmrc, if you're using the default window manager, for further customizations.

-- JJ



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.