How To Install VNC Server On CentOS

VNC (Virtual Network Computing ) is a graphical desktop sharing system that uses the Remote Frame Buffer protocol to remotely control another coumputer on a network.

To run the VNC Server on CentOS, we have to install these required packages:

Code: [Select]
yum groupinstall Desktop
yum install tigervnc-server
yum install xorg-x11-fonts-Type1
yum install vnc

To start VNC Server on boot

Code: [Select]
chkconfig vncserver on

To setup users’ VNC password:

Code: [Select]
vncpasswd

Edit the /etc/sysconfig/vncservers file:

Code: [Select]
nano /etc/sysconfig/vncservers

Add the following to the end of the file:

Code: [Select]
VNCSERVERS="1:arbab"
VNCSERVERARGS[1]="-geometry 1024x600"

The iptables rules need to be amended to open the VNC ports:

Code: [Select]
iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp -m multiport --dports 5901:5903,6001:6003 -j ACCEPT
service iptables save
service iptables restart

Restart the VNC Server:

Code: [Select]
service vncserver restart

Now kill the VNC Server:

Code: [Select]
vncserver -kill :1

Edit the xstartup file in .vnc directory:

Code: [Select]
nano .vnc/xstartup

Comment the last line and run the Gnome:

Code: [Select]
 #twm & 
exec gnome-session &

Restart the service:

Code: [Select]
service vncserver restart

Now, download VNCViewer onto our desktop computer from which we want to access the shared desktop.
Connect using ServerIP/Name:1 (:1 is for the VNC server window)

http://www.realvnc.com/download/viewer/

Enter the password that we created using the vncpasswd command:

Ability to connect for multiple users:

Create a local user, using the following command:

Code: [Select]
adduser ali

Create a password for newly created user:

Code: [Select]
passwd ali

Switch to the newly created user and run vncpasswd command for it:

su ali

Code: [Select]
vncpasswd

Edit the /etc/sysconfig/vncservers file:

Code: [Select]
nano /etc/sysconfig/vncservers

Add these lines for new user:

Code: [Select]
VNCSERVERS="1:arbab 2:ali"
VNCSERVERARGS[1]="-geometry 1024x600"
VNCSERVERARGS[2]="-geometry 1024x600"

Restart the VNC service:

Code: [Select]
service vncserver restart

Kill the vncserver session for new user and edit the xstartup file:

Code: [Select]
su ali
vncserver -kill :2
cd ~
nano .vnc/xstartup

Modify the file so it looks like this:

Code: [Select]
 #twm & 
exec gnome-session &

Restart the VNC service:

Code: [Select]
service vncserver restart

Connect with newly created user using centos:2, Where centos is my server name:

Enter the password that we created using the vncpasswd command: