There is a new version of this tutorial available for CentOS 8.

VNC Server Installation on CentOS 6.5

Version 1.0
Author: Srijan Kishore

This guide explains how to configure VNC-server in CentOS 6.5 server. It is a very convinient way of administrating the CentOS 6.5 with the help of GUI(Graphics User Interface). The GUI can be access any where with the help of the VNC-client on any OS. The basic condition is that the connecting OS must have VNC-clients installed in it.

1 Preliminary Note

In my case I have a fresh installed CentOS6.5 Server on which I will be installing the VNC-server so that I can access the CentOS server with GUI. You can follow the guide for the basic installation of the CentOS server till Chapter 7. Please don't install the Development Tools. All of the cases are same as per the guide. My details are as follows:

IP address 192.168.0.100
Gateway 192.168.0.1
DNS     8.8.8.8    8.8.4.4
Hostname server1.example.com

VNC-server benefits

  • Remote GUI administration makes work easy & convenient.
  • Clipboard sharing between host CentOS server & VNC-client machine.
  • GUI tools can be installed on the host CentOS server to make the administration more powerful
  • Host CentOS server can be administered through any OS having the VNC-client installed.
  • More reliable over ssh graphics.
  • More reliable over RDP connections.

2 Installation

I am logged in my system with root, & now I will be installing the VNC-server.

yum groupinstall Desktop

Further install

 yum install gnome-core xfce4 firefox
 yum install tigervnc-server

Now make the service on after every reboot

chkconfig vncserver on



3 Adding VNC user

In my case I am using user=srijan it will differ in your case. You can use any username for the same.

useradd srijan


Now I will assign the vncpassword for the user with the user I just created before as:

su - srijan
vncpasswd


[[email protected] ~]# su - srijan
[[email protected] ~]$ vncpasswd
Password:<--yourvncpassword
Verify:<--yourvncpassword
[[email protected] ~]$



Now I will make the configuration file for the vncserver  by creating file as follows:

vi /etc/sysconfig/vncservers

Give the entries like this.

[...]
VNCSERVERS="1:srijan" VNCSERVERARGS[1]="-geometry 1024x768"

Here your port comes to be 5901 & 1024x768 resolution for the VNC client, you can choose resolution of your own choice.

Now I will restart the VNC server service as root user:

service vncserver restart

[[email protected] ~]# service vncserver restart
Shutting down VNC server:                                  [  OK  ]
Starting VNC server: 1:srijan xauth:  creating new authority file /home/srijan/.Xauthority

New 'server1.example.com:1 (srijan)' desktop is server1.example.com:1

Creating default startup script /home/srijan/.vnc/xstartup
Starting applications specified in /home/srijan/.vnc/xstartup
Log file is /home/srijan/.vnc/server1.example.com:1.log

                                                           [  OK  ]
[[email protected] ~]# 

Now to make the changes affective I will kill VNC & do some more configurations as follows:

pkill vnc

Open the file comment the line #twm & & add the line exec gnome-session as follows:

vi /home/srijan/.vnc/xstartup
#!/bin/sh

[ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
export LANG
export SYSFONT
vncconfig -iconic &
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
OS=`uname -s`
if [ $OS = 'Linux' ]; then
  case "$WINDOWMANAGER" in
    *gnome*)
      if [ -e /etc/SuSE-release ]; then
        PATH=$PATH:/opt/gnome/bin
        export PATH
      fi
      ;;
  esac
fi
if [ -x /etc/X11/xinit/xinitrc ]; then
  exec /etc/X11/xinit/xinitrc
fi
if [ -f /etc/X11/xinit/xinitrc ]; then
  exec sh /etc/X11/xinit/xinitrc
fi
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
exec gnome-session &


& Finally reboot the machine.

reboot

4 VNC Client

At client end my OS is Ubuntu14.04 with vino installed on my client machine. Otherwise you can install any VNC-client of your choice. In case other OS say windows-7 you can install Realvnc-client or any other of your choice.

Again start the vncservice with the user srijan:

su - srijan
vncserver

[[email protected] ~]# su - srijan

[[email protected] ~]$ vncserver

New 'server1.example.com:1 (srijan)' desktop is server1.example.com:1

Starting applications specified in /home/srijan/.vnc/xstartup

Log file is /home/srijan/.vnc/server1.example.com:1.log

[[email protected] ~]$

Now I am going to connect with the VNC server through my VNC-client

It will prompt for the password as follows:

Put yourvncpassword the same which you gave at the time of adding the user srijan.




Now you are connected with the CentOS6.5 Server. In case you want to add more users to access the vnc-console you need to add the user, assign the vncpassword for the new-user as mentioned above & append the entry in the file as:

vi /etc/sysconfig/vncservers

For instance I am using user kishore, entries will be like this

[..]
VNCSERVERS="2:kishore"
VNCSERVERARGS[2]="-geometry 1024x768"



This will enable user kishore to get the access to the VNC-server with the port 5902. In the same way you can add the root user also.





Congrats you have configured the VNC-server successfully :) 

Share this page:

17 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Anonymous

It works, thanks. However, I faced 2 small issues on centOS6.5. Firstly, had to add iptables rule to allow vnc port. Secondly, had to set the password for the vnc user. The password is needed because, the screen gets locked after a while and if no password is set then all unlock attempts fails

By: bondo

Had to do this and restart the vncservice

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
 
 

 

By: prakash

It's great tool and easy to manage all things of linux GUI.

Thanks,

Prakash

By: Mario

Something changed for CentOS 6.6 because I can't get this work. I tried bondo's iptables command and that returned an "unknown protocol '-m' specified."

Anyone have suggestions?

By: hank

On Remmina client for ubuntu the VNC configuration requires the user ID not the port.

server: [ip]:1    or      server: [server1.example.com]:1

 

By: Yigit

Hi. Can you help?CentOS 6.7 / firewall disabled

/etc/sysconfig/vncservers# VNCSERVERS="5901:admin"# VNCSERVERARGS[5091]="-geometry 1024x768"

[[email protected] ~]# service vncserver restartShutting down VNC server:                                  [  OK  ]Starting VNC server: no displays configured                [FAILED]

Where I could have done wrong?

By: bob

You don't need to specify the complete port string. The number you assign to each user will be concatenated to the first three digits of the vnc default ports (i.e. 590 + the_number_you_specify). In your code, the actual port for connection ends up being 5905901, which is, of course, nonsensical. Just remove the 590 and leave the 1 like so: "1:admin"  and VNCSERVERARGS[1] and you should be good to go. 

By: Poonchezhian

Srijan,

I want to make the vncserver as service, so it's always running and i can connect to the client even after the reboot. what has to be enabled?

By: till

The command:

 

chkconfig vncserver on

 

should enable the service to start at boot. If this won't help, then add the command:

 

service vncserver start

 

in the file /etc/rc.local

By: GE

Why do you say, "Please don't install the Development Tools." Is there a conflict? I need the development tools.

By: Hai

Hi,

I have a VPS with CentOS 6 and I installed VNc server to connect to it. Everything works fine, network and internet are ok. But after I reboot the VPS, I can connect the VPS through VNC again but the VPS does not have internet, the network icon showing "red X" with the message "device not managed".I have tried to rebuild the VPS, install VNC and the internet problem comes again after reboot.

By: root

This worked for me on CentOS 6.8 nicely. Thanks for the good tutorial.

By: V

In my case "yum groupinstall Desktop" failed because such groupinstall was not found at centos 5 with epel and remi repo.

By: Amish

Hello,

It's working fine, but firefox is displaying blank screen after loading of webpage, how do i solve this issue ?

-Amish 

By: Emrul Hasan

How way I can enable internet access throw VNC. I am tried to finding this soluation. Please help me to fixing this problem I need to brow webbrowser at VNC on Centors OpenVZ.

By: mariomp24

I did everything as described.

The VNC server is running, and I am also on the desktop.

But I get the internet connection to run

By: Michael

100% did not work for me.

I keep gettin xauth:  file /root/.Xauthority does not exist

xauth: (stdin):1:  bad display name "s14###.wholesaleinternet.net:4" in "add" command

over and over and over