This post has already been read 4260 times!
Every day when I finish work, I switch off my desktop computer. When I switch it on again the following morning, I can carry on where I left off. I switch on the computer, and all of my application windows are exactly where I left them. The web browser is still showing me the webpage I was half-way through reading. How? I use Virtual Network Computing: VNC.
My desktop session actually runs on another machine in another building. The desktop computer I sit in front of runs a VNC viewer and shows me my desktop—but the applications in that desktop are running inside a VNC server session.
Applications of VNC
There are several different problems that can be solved by using VNC. The reason I use it is so that I can have a persistent desktop as previously described. This is one of the most common reasons for using VNC. One computer runs a VNC server, which is a type of virtual frame buffer: it manages a screen image (a two-dimensional array of pixels), but does not display it directly on a screen. Another computer runs a VNC viewer, which acts as a client and takes the frame buffer image from the VNC server and displays it on a real screen. With VNC providing a persistent desktop, I do not need to log in or log out, but instead I just resume my session from where I left off last time by running a VNC viewer application.
VNC servers and viewers are available for a variety of operating systems. Red Hat® Enterprise Linux® 4 includes the server and two viewers: a Java version as well as the native application. The VNC server can be configured to provide the Java viewer over HTTP, so you can use any Java-enabled web browser on any operating system as a VNC viewer.
The design of VNC places few demands on the VNC viewer. Most of the work is done by the server. As a result of this, it is a well-placed technology for making thin client systems (where a number of diskless machines provide graphical interfaces to a single powerful server). Thin clients need only run the VNC viewer whereas the applications can reside on the server.
One type of thin client is an X terminal: a dedicated machine that runs the X Window System and is connected to a network. In general, these machines are configured to connect to a server which then displays a login window. The X terminal displays the graphics from the server using the X Window System protocol.
A VNC viewer can act like a software X terminal, with a VNC server providing the login window. The advantage of using VNC for this is that the login session will stay there even when the user disconnects the VNC viewer, moves to another room or building, then reconnects. The session only finishes when the user logs out; afterwards, connecting with a VNC viewer will show a login window again.
Another use for VNC is to remotely control or view a display. Several methods for doing this are included with Red Hat Enterprise Linux 4. The easiest to use is the Remote Desktop entry in the Main Menu -> Preferences menu. To allow your session to be viewed or controlled, click the check buttons labeled Allow other users to view your desktop and Allow other users to control your desktop. In this dialog box you can also set a password for VNC access and ask require when a VNC viewer connects as shown in Figure 1. Remote desktop.
A less easy but more efficient way of achieving the same effect is to use the VNC loadable module for the X Window System. Instructions for setting this up can be found at the RealVNC website. Using this module, even when no one is logged in, the login window on the screen can be viewed and controlled remotely.
With Red Hat Enterprise Linux 4, VNC can make life easier even while you install the operating system! You probably already know that unattended automatic installations are possible using the kickstart feature, with the installation options and package selections being set out in advance in a kickstart file. You may not know that you can have interactive control of the Red Hat Enterprise Linux installation procedure even when the machine being installed is physically remote from you, perhaps even in another country.
The installing Red Hat Enterprise Linux machine can be told to act as a VNC server from the very beginning of the installation. Very briefly, the way to do this is to boot using PXE (or any similar method), passing the command line linux ks vnc to the installer (links to documentation about PXE network installations can be found in the section called “Further reading”). Provide a minimal kickstart file using DHCP, which just sets the location of the installation directory—perhaps an NFS server. When the installer starts you will be able to start a VNC viewer and connect to the IP address of the machine.
Setting up a persistent desktop
Here is a description of the steps to take when setting up a persistent desktop using VNC in Red Hat Enterprise Linux 4.
The first thing to do is set a password for the VNC server. To do this, log in as normal and run the command vncpasswd from a shell prompt. The VNC service will not start unless you have set a password.
Next, become root using su - and edit the /etc/sysconfig/vncservers file. To set up two persistent desktop sessions, one for fred and one for joe (who prefers a larger display size than fred), it should look like Example 1. /etc/sysconfig/vncservers example.
# The VNCSERVERS variable is a list of display:user pairs.
# Uncomment the line below to start a VNC server on display :1
# as my 'myusername' (adjust this to your own). You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that.
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, see
# fred's VNC options
# joe's VNC options
Example 1./etc/sysconfig/vncservers example
To start all VNC persistent desktops at boot, enable the VNC service with chkconfig vncserver on (as root). Then, to start the VNC persistent desktops now, type service vncserver start. Both users will be able to connect VNC viewers, fred to display number 1 and joe to display number 2.
The default desktop session in VNC is a very simple one, using the twm window manager. You might prefer the VNC desktop session to look and behave the same as the login session you would normally see. To do that, edit the file /home/username/.vnc/xstartup and remove the # from the beginning of the two lines that follow the line reading Uncomment the following two lines for normal desktop.
Using a VNC viewer
Whether you use the Java VNC viewer or a native VNC viewer on Red Hat Enterprise Linux 4, Microsoft® Windows®, or any other platform, the procedure is broadly the same. On Red Hat Enterprise Linux 4 the application can be found in the menu as Main Menu -> Accessories -> VNC Viewer.
A dialog box will appear asking for a VNC server to connect to, and an Options... button allows you to configure certain things about how the VNC viewer will operate.
The VNC server is identified by a hostname (or IP address) and a display number. If the /etc/sysconfig/vncservers file in Example 1. /etc/sysconfig/vncservers example was on a machine named hoopoe.elk, the VNC server for joe's session would be hoopoe.elk:2.
The VNC display number is not an IP port number even though the hostname:number syntax is used for specifying port numbers in a web browser. To make matters slightly more confusing, the Java VNC viewer is accessed in this way when using a web browser by specifying a port number! The port number for the Java VNC viewer is the display number plus 5800. For example, to get to joe's VNC session using a web browser the URL would be http://hoopoe.elk:5802/.
If a password is set on the VNC server, the VNC viewer prompts you for it. Next, the VNC viewer window appears containing the desktop session (see Figure 2. VNC Viewer window). Closing the VNC viewer window does not terminate the desktop session.
To adjust connections settings, press F8 for the menu (refer to Figure 3. VNC Viewer menu. Running a VNC viewer in Full screen mode allows it to catch key combinations that would normally be intercepted by the window manager, for example Alt-Tab to switch between windows. In Full screen mode, this switches between windows in the VNC session, not between the VNC viewer window and other windows on the local session.
Pressing F8 brings up the VNC menu, but if you want an application running in the VNC session to get the keypress instead of the VNC viewer, select Send F8 from the VNC menu.
Here is a quick recap of the steps needed to set up a persistent desktop using VNC on Red Hat Enterprise Linux 4.
Set a password using vncpasswd
Enable the service with chkconfig vncserver on
Start the service with service vncserver start
Edit /home/username/.vnc/xstartup if you want a more advanced session than just twm and an xterm