How to install VNC server on CentOS 6

VNC is a protocol that is used to share the desktop with other users/computers over the network/Internet.In order to share a desktop, VNC server must be install and configure on the computer and VNC client must be run on the computer that will access the shared desktop.

When we install the minimal copy of CentOS Server, it only gives us the “Command Line” interface.

But some people prefer GUI instead and for this they install Full version of Gnome on CentOS. Actually there is a better way and that is to install VNC. VNC provides a lightweight virtual desktop than full blown version of Gnome.

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

sudo yum groupinstall Desktop

sudo yum install tigervnc-server

sudo yum install xorg-x11-fonts-Type1

This is optional:

sudo yum install vnc

To start VNC Server on boot

sudo chkconfig vncserver on

To setup users’ VNC password:

vncpasswd

Edit the /etc/sysconfig/vncservers file:

sudo nano /etc/sysconfig/vncservers

Add the following to the end of the file:

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

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

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

Restart the VNC Server:

sudo service vncserver restart

Now kill the VNC Server:

vncserver -kill :1

Edit the xstartup file in .vnc directory:

nano .vnc/xstartup

Comment the last line and run the Gnome:

#twm & 
exec gnome-session &

Restart the service:

sudo 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), In my case it is centos:1.

Enter the password that we created using the vncpasswd command:

We now have GUI access to our server.

Ability to connect for multiple users:

Create a local user, using the following command:

sudo adduser ali

Create a password for newly created user:

sudo passwd ali

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

su ali
vncpasswd

Edit the /etc/sysconfig/vncservers file:

sudo nano /etc/sysconfig/vncservers

Add these lines for new user:

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

Restart the VNC service:

sudo service vncserver restart

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

su ali
vncserver -kill :2
cd ~
nano .vnc/xstartup

Modify the file so it looks like this:

#twm & 
exec gnome-session &

Restart the VNC service:

sudo 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:

We now have GUI access to our server for newly created user.

Hope this will help you!

Please Remember me in your prayers!

Enjoy 🙂

28 responses to “How to install VNC server on CentOS 6

  1. Pingback: How to Encrypt VNC Traffic with Putty « Lazy Geek -:)

  2. Marko December 2, 2012 at 10:25 pm

    Thanks for great tutorial. I spend more than 4 hours trying to setup VNC on Ubuntu, and finally move to CentOS and with this tutorial I setup VNC in 10 min. Thanks 😉

  3. melwynjensen January 8, 2013 at 6:44 pm

    Awesome! Just followed the steps and worked like a charm!!!

    Continue doing more like this :):)

  4. Pingback: CentOS 6.3 :: Setup VNC Server | :: b l a c k o n s o l e ::

  5. Ruben Saldivar (@rsaldivarp) February 15, 2013 at 10:59 pm

    Thanks, very nice document, for me was necesary to consult http://phylevn.mexrom.net/index.php/blog/show/Como_configurar_Servidor_VNC_para_KDE__Gnome_.html for KDE setup.. even on that, very helpful document.

  6. Pingback: CentOS 6.2 setup questions

  7. Md.Murad Hosen April 21, 2013 at 10:24 am

    It is very Useful Tutorial.It is work 100%.Carry on.

  8. Pingback: Centos VNC Kurulumu

  9. Daniel May 7, 2013 at 4:57 pm

    Extremely helpful! Thank you!

  10. Ashish July 18, 2013 at 6:07 pm

    It worked like charm..!!
    Thanks You..

  11. Jonathan Atkins August 29, 2013 at 10:59 am

    Starting VNC server: no displays configured [FAILED]
    what did i do wrong?

  12. Ricardo Pinto September 13, 2013 at 3:06 pm

    Hi, thanks for your post, it has been really helpfull. I got the following message: “Index of insertion too big.” when opening the vnc ports – “sudo iptables -I INPUT 5 -m state –state NEW -m tcp -p tcp -m multiport –dports 5901:5903,6001:6003 -j ACCEPT”

    could you help me?

  13. salahar September 29, 2013 at 9:05 am

    when i inter this “sudo iptables -I INPUT 5 -m state –state NEW -m tcp -p tcp -m multiport –dports 5901:5903,6001:6003 -j ACCEPT” its says index of intersation too big help pls

  14. François December 12, 2013 at 2:18 pm

    Excellent tuto.
    Thanks

  15. Ridha February 18, 2014 at 8:11 pm

    Best tutorial
    Thank you brother

  16. lim February 24, 2014 at 9:43 am

    Really Very good stuff Many Thanks for upload

  17. M.L. March 21, 2014 at 9:02 pm

    Is there any way to have always an encrypted connection? Please advise.

  18. Pingback: nothingOS » VNC Centos Guide

  19. SlackerZeitgeist June 26, 2014 at 8:06 pm

    Really great tutorial. Made setting it up a breeze. Thanks so much!

  20. Dave August 25, 2014 at 8:46 pm

    Excellent tutorial! Many Thanks

  21. Gagan Pal August 30, 2014 at 1:50 am

    Your Tuts are really good, simple and straight to the point. However this time, I drifted a little bit from your tut, as I wanted to keep X at bare minimum. I installed XFCE on CentOS6.5 “Minimal”.
    I’m doing this in virtual box.

    X loads fine on the Virtual Machine, but when connecting via VNC, the Desktop loads but there is just a blank “blue” XFCE Background with no icons/taskbar etc. Mouse is movable but nothing can be done. On regular hardware with intel graphics I got this problem but installing intel graphics resolved it for me. How to do this for the Virtualbox?

  22. Ballu Chegu October 17, 2014 at 2:34 am

    Fixed “index of intersation too big”. You need to append to the table, instead of inserting at line 5. Execute this: iptables -A INPUT -m state –state NEW -m tcp -p tcp -m multiport –dports 5901:5903,6001:6003 -j ACCEPT

  23. iamjeffvader December 24, 2015 at 5:10 am

    simply awesome, thanks.

  24. Pingback: Como instalar o VNC server no CentOS 6.x – UNIX LINUX

  25. Shewky Whiteiron February 9, 2019 at 2:40 pm

    The best solution ever for Centos 6! Thanks alot!! Can you also share like this for Centos 7 ? THANKS

Leave a comment