VNC Server configuration for linux

Check what's installed
First check if you already have them installed on your system, open a terminal and type:
[root@localhost ~]# rpm -qa | grep -i vnc*
vnc-server-4.1.2-14.el5_3.1
vnc-4.1.2-14.el5_3.1
If package does not exist then need to install this package
[root@localhost ~]# yum install vnc* -y
[root@localhost ~]# vim /etc/sysconfig/vncservers
VNCSERVERS="2:root"
 VNCSERVERARGS[2]="-geometry 800x600 -depth 16 "
The important part is the VNCSERVERS="1:root", this sets up a users for the vnc server, you can add as many as you like here. The VNCSERVERARGS[1]
line refers to the arguments for user 1, in this case the only user. Geometry sets the size and depth sets the colour depth, you can adjust these to
suit your preferences but in my case the client machine has a resolution of 1024x768 and the depth 16 makes the connection a bit faster since the less
Setting a password
To add some security we need to add a password that must be given before a connection can be established, open a terminal and type:
[root@localhost ~]# vncpasswd
Password:
Verify:
[root@localhost .vnc]# vim /root/.vnc/xstartup
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
[root@localhost .vnc]# chmod 770 /root/.vnc/xstartup
[root@localhost .vnc]# /etc/init.d/vncserver restart
Shutting down VNC server: 2:root                           [FAILED]
Starting VNC server: 2:root xauth:  creating new authority file /root/.Xauthority

New 'localhost.localdomain:2 (root)' desktop is localhost.localdomain:2

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:2.log

                                                           [  OK  ]

Now we  will access VNC Server with TightVNC Server software :
 








For exit press SHIFT+CTRL+ALT+F
Stopping the vncserver
There are two ways to stop the server, either as root:
$ /sbin/service vncserver stop
Shutting down VNC server: 1:bobpeers                        [  OK  ]

or you can explicitly kill a particular session without being root:
$ vncserver -kill :1
Killing Xvnc process ID 13728

Just replace the 1 with the vnc session you wish to stop.