How to configure VNC server in Linux (Red Hat)

Virtual Network Computing (VNC) is a graphical system that is used to remotely control another computer. It transmits the mouse and keyboard events from one computer to another, relaying the graphical screen updates back in the other direction, over a network.

Prerequisites before starting the configuration of VNC server in CentOS 5:

Make sure the required packge is installed in the machine.

# rpm -qa | grep vnc  

If you do not get the output packages then install then using yum

# yum -y install vnc-server  

Once the package is installed these are the steps you need to follow

# vi /etc/sysconfig/vncservers  
 on the line 20  
 VNCSERVERS="2:root" <== give the username of the user by whom you want to use vncserver as in my case root  

Assign a password for the vncserver for the root user

# vncpasswd  
Password:  
Verify:

and restart your vncserver using this command

# service vncserver restart  

If the service starts without any error then you can move to the next step or else check for the log messages which you can find in

# less /var/log/Xorg.0.log  

Now I will assume that the service started without any error So for the next step

# vi /root/.vnc/xstartup  
# go to line no. 5 and uncomment it  
 exec /etc/X11/xinit/xinitrc <===uncomment this line  

save and exit
Restart the service# service vncserver restart

open the client software i.e vnc client

9 27 20124 07 49PM

9 27 20124 08 02PM

Prerequisites before starting the configuration of VNC server in CentOS 6:

The vncserver package in CentOS 6 and RHEL 6 is different as compared to earlier versions to which most of us get confuse.
Installing vnc-server rpm

# yum -y install tigervnc-server  

Once the package is installed

# vi /etc/sysconfig/vncservers  
 # on the line 18  
 VNCSERVERS="2:myusername" <== give the username of the user by whom you want to use vncserver as in my case root  

Assign a password for the vncserver for the root user

# vncpasswd  
Password:  
Verify:  

and restart your vncserver using this command

# service vncserver restart  

In CentOS 6 you do not need to edit any other file from here you can use the same steps as I described earlier using the client software to connect your vncserver.