Solution:
1. First, check whether the required VNC package has been installed. Run this command as the root user:
rpm -qa | grep vnc
If the RPM command outputs vnc-doc, vnc-server, and vnc, go to step 2. If the RPM command is not output, run this command to install the required package, and then go to step 2:
up2date vnc vnc-server vnc-doc
Assume that your system has been registered with the Red Hat Network (RHN) and you have an active authorization. Otherwise, you need to install the RPM package from the installation media.
2. Log On As a vnc user or switch to this user (using su-username ). If VNC needs to be configured as multiple users, repeat steps 2 to 4. When all users are set, perform Step 5.
3. Execute this command and replace Z with a number greater than zero.
vncserver :Z
The number Z represents the X session, and the user permanently assigns this number to their VNC-based X session.
Note: In this tutorial, each time the letter Z appears, it should be replaced with an appropriate number, representing the user-configured VNC-based X session. The X session running on the console uses the number 0, so Z should be equal to or greater than 1. Every user of a VNC-based X session configuration needs to replace Z with their own unique number.
When the command is run for the first time, the $ HOME/. vnc directory will be created for the user and a VNC password will be entered. This password is required when the VNC viewer program is connected from a remote machine. If you want to change the password, run the following command:
vncpasswd
4. VNC uses the twm window manager by default. If you want to use GNOME (Red Hat Enterprise Linux default environment) or KDE Desktop Environment, edit the $ HOME/. vnc/xstartup file and note out the lines starting with xterm and twm. If you want to use GNOME, add a line at the end of the file:
gnome-session &
If you want to use KDE, add this line:
startkde &
Now the desktop has been set. To make it take effect, you must kill and restart an existing VNC-based X session. Run the following two commands to kill and restart the VNC session:
vncserver -kill :Z vncserver :Z
5. Edit the/etc/sysconfig/vncservers file. Find the line starting with VNCSERVERS, remove the comment, and add all VNC sessions that should be automatically started during system reboot, such:
/etc/sysconfig/vncservers VNCSERVERS="1:root 2:bob 3:carol"
Make sure that each user matches the appropriate number Z selected in step 3.
6. Set VNC to start during system boot. Run the following command:
chkconfig --level 345 vncserver on
After the computer restarts, The VNC-based X session is automatically started when the/etc/sysconfig/vncservers file is written.
Now that VNC is running, this command can be used to connect to a suitable VNC-based X session from a remote Linux machine:
vncviewer servername:Z
If the remote machine runs Red Hat Enterprise Linux but the vncviewer program is not installed, run this command as the root user to install it:
up2date vnc
If the remote machine system is running Windows, you can download a VNC viewer program under Windows for free, URL: http://www.realvnc.com
After you use VNC, these VNC-based X sessions must run. To do this, you can simply close the vncviewer program instead of logging out. In this way, the desktop status will be saved. When the user reconnects, all their programs will be in the status when they last left. If a user unexpectedly exits from a VNC-based X session, perform the following steps to allow X to work again:
1. Log in to the server as the user who needs VNC restart.
2. Enter the command: vncserver -kill: Z
3. Run vncserver: Z
This will kill and restart the VNC-based X session. Make sure that the user uses the correct 'Z' number. If an application has been started on a VNC-based X session, you need to obtain it from the local terminal. Run the following command:
vncviewer 127.0.0.1:Z
Replace Z with the number of the VNC-based X session that the program runs.