Install VNC Server on CentOS 6.x server

Most of the time system administrators manage servers over the network or internet. It is very rare that a physical access is required. Now a days with cloud and stuff happening a Linux admin just need a SSH access to the server for day to day tasks. However, VNC allows to open a remote GUI session to your server and  provides full graphical interface accessible from any remote location.

Here are some quick installation and configuration steps to start with;

Login as root and run the follwoing

# yum install vnc-server

This will be a very quick installation, when done edit VNC Server Config File

# vi /etc/sysconfig/vncservers


where num is equals 1 to 9, which are tcp ports 5901-5909, you will need to open these ports in iptables if you are using it.

USER = user, please create a non root your if you haven’t done it yet
WIDTH = horizontal resolution for desktop
HEIGHT = vertical resolution for desktop

To create a VNC server for port 5808 for user “myuser” with 1024×768 resolution,  you can use the following configuration:
VNCSERVERARGS[1]=”-geometry 1024×768″

Set the VNC Password for myuser
Login as myuser, and set the VNC password
# su – myuser
[myuser@host ~] vncpasswd
[myuser@host ~]

Time to start the VNC server

As root run the following command,
# service vncserver start

To make sure that VNC runs with each reboot, you may optionally enable the service for reboots
# chkconfig vncserver on

Connecting VNC server
Any windows, mac or linux-based VNC viewer can be used to connect to the VNC desktop.  Recommend “TightVNC” as open-source Windows viewer.
When connecting, connect to hostname:disp#, so for the above

Connect with: TightVNC Server: hostname:8

Opening VNC ports in firewall [iptables]

VNC server listens on 580x, 590x, and 600x TCP ports. Java based vncviewer connects on 5800x ports, Windows based connects on 5900x ports and and X-Server connects on 6000x ports.

Edit /etc/sysconfig/iptables file:
# vi /etc/sysconfig/iptables

Update it as follows, for our example use

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 5801  -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 5901  -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 6001  -j ACCEPT

Save and close the file. Restart iptables:
# service iptables restart


Leave a Reply

Your email address will not be published. Required fields are marked *