Linux Project

VNC
Thursday, 11 Apr 2002

VNC is a remarkable program that makes huge strides in the direction of Linux-Windows interoperability. It is based on the client-server model. Start the vnc server on the remote machine (Linux or Windows) and use the vnc client, called the "vncviewer," on the local machine to connect to that server. The result is a remarkably lifelike view of the desktop of the remote machine appearing in a window of the local machine or even completely taking over the entire viewing area of the monitor of the local machine. And not only does the display appear to be alive, it IS alive. List your files on the remote machine, open emacs, compile and run something, and all those processes will run on the remote machine and display on the local machine, never mind that there may be completely different machines and operating systems involved. This remarkable achievement is a product of some very talented people at AT&T. The software can be freely downloaded and installed on your machines. Response time is usually quite good on a local network but may deteriorate severely over a wide-area network.

We will be using three commands to manipulate the vnc system:

Acknowledgements: Many thanks to Steve Marlowe, Sewanee '02, for the explorations that lead to these notes.

Setting up the vnc client and server on two Linux machines

1. The first step is to install the software on your machine. The package tightvncserver.rpm can be found on calypso:/home/cs428 and thebe:/home/cs428, Use ftp or gftp to copy it to your working directory. Alternatively, you may download the rpm package or source code from the Tight VNC download area. Install the rpm as root with the command rpm -Uvh tightvncserver.rpm

[root@pluto rpms]# rpm -Uvh tightvncserver.rpm 
Preparing...                ########################################### [100%]
   1:vnc-server             ########################################### [100%]

Important Security Note: The following directions show root setting up and then running vnc sessions. That may be convenient for a first training session with this software, but it opens up a very large security gap. Anyone succeeding in connecting to root's session then has remote access to ALL of root's authority on that machine. As Steve Marlowe points out, "It is probably better for them [the users] to start the server logged in as normal users. This also allows each user to customize his vncserver using different xstartup scripts, different geometry, color depth, etc."

2. Connections to a vnc server are password protected. Establish a password for these sessions and install certain configuration files in your home directory by invoking vncpasswd from your home directory. Enter and verify your password.

[root@pluto root]# vncpasswd
Password: 
Verify:  

The directory .vnc has just been created in your home directory.

[root@pluto root]# ll .vnc
total 4
-rw-------    1 root     root            8 Jan 30 20:02 passwd

3. Start the vnc server with the command vncserver & and wait a few seconds for an explanatory message to appear.

[root@pluto root]# vncserver
New 'X' desktop is pluto:1

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/pluto:1.log


[2]+  Done                    vncserver

This launches the vnc server and creates certain configuration files under the directory .vnc in your home directory.

4. Now go to a remote machine and connect to your server with a command of the form

vncviewer <machine name or IP address>:<display number - parameter to vnc server>

For instance, you might type

vncviewer pluto:1

You will be prompted for your vncpasswd. Enter the password to make a connection. If you see the desktop of the remote machine in a window on the local machine, your system is working!

However, you will quickly discover that when vnc comes right out of the box it is running an exceedingly modest window manager named twm. The world long ago went on to bigger and better things, and you can too.

4. To use a better window manager, go back to the server machine and, in your home directroy, open emacs on the file .vnc/xstartup.

!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &

Edit that file as follows:

#!/bin/sh

# xrdb $HOME/.Xresources
# xsetroot -solid grey
# xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
# twm &

"$VNCDESKTOP Desktop" &
gnome-session&

or, alternatively,

"$VNCDESKTOP Desktop" &
kde&

Invoking "gnome" and "kde" will start sessions using those desktop managers, just as if you had chosen those options from the remote computer's login screen. If you normally use Ximian Gnome, the "gnome-session" may select that version of gnome. Now start the server and check the desktop number it assigns to this session, in this case :1.

[root@rosalind .vnc]# vncserver

New 'X' desktop is rosalind:1

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/rosalind:1.log

Notice that certain changes have occurred in the directory .vnc. Listing .vnc when no server is running yields something like the following:

[root@rosalind .vnc]# ll
total 5
-rw-------    1 root     root            8 Jan 30 15:42 passwd
-rw-r--r--    1 root     root         1317 Jan 30 15:43 rosalind:1.log
-rwxr-xr-x    1 root     root          172 Jan 30 15:55 xstartup
-rwxr-xr-x    1 root     root          124 Jan 30 15:43 xstartup~

But listing .vnc when the server is running yeilds

[root@rosalind .vnc]# ll 
total 5
-rw-------    1 root     root            8 Jan 30 15:42 passwd
-rw-r--r--    1 root     root          604 Jan 30 16:05 rosalind:1.log
-rw-r--r--    1 root     root            5 Jan 30 16:05 rosalind:1.pid
-rwxr-xr-x    1 root     root          172 Jan 30 15:55 xstartup
-rwxr-xr-x    1 root     root          124 Jan 30 15:43 xstartup~

In particular, the file rosalind:1.pid contains the pid of your server.

When it comes time to kill the server, use a command of the form vncserver -kill <X-display>.

vncserver -kill :1

It is important to kill the server before terminating a session. If there are several servers running, kill them selectively by targeting each one's display number.

vncserver -kill :2; vncserver -kill :3; vncserver -kill :5

There are many server options available and it is fun to experiment with them.

[root@rosalind .vnc]# vncserver --help

usage: vncserver [:] [-name ] [-depth ]
                 [-geometry x]
                 [-pixelformat rgbNNN|bgrNNN]
                 ...

If your screen size is 1024x768 you might wish to make the displayed window a little bit smaller to fit on the host desktop, say 1000x700. Type Xvnc to see your options, eg. sharing, and try out a few combinations.

vncserver :5  -depth 24 -alwaysshared -once

Here,

VNC Exercise: Set up the VNC client and server on a PC

Set up the vnc client and server on a PC and experiment with Linux-Windows connectivity. Use telnet on the local machine to connect to the remote machine and start the vnc server there. Use the local vncviewer to control the remote machine. Try running several precesses on the remote machine. What sort of response times are you getting? How convenient is this sort of connectivity? Is it useful enough to provide access to lab machines from your home computer or vice-versa?

VNC Exercise: Use a web browser as a VNC client or install the VNC client and server on a Macintosh

Instructions are available at the VNC web page. OSXvnc is a vnc server for Mac OS X. There are several VNC clients available for Mac OS X, including VNCviewer, another VNCviewer, VNCThing, and VNCDimension. Using OSXvnc as the server and VNCThing as the client has worked well for us on Mac OS 10.1.3 for Macintosh-Linux connectivity.


cparrish@sewanee.edu