VNC-Server installation on CentOS 7

Version 1.0
Author: Srijan Kishore

This guide explains how to configure VNC-server in CentOS 7.0 server. It is a very convinient way of administrating the CentOS 7.0 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

This tutorial is based on CentOS 7.0 server, so you should set up a basic CentOS 7.0 server installation before you continue with this tutorial. The system should have a static IP address. I use 192.168.0.100 as my IP address in this tutorial and server1.example.com as the hostname.

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 "GNOME Desktop"

Further install

 yum install tigervnc-server

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

In CentOS 7.0 there is change in the vncserver configuration file. Before ContOS 7.0 it was  /etc/sysconfig/vncservers and now it have changed in /lib/systemd/system/vncserver@.service. Next I will use the original file and create the configuration file as shown:

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service


Now we will edit the file as follows:

vi /etc/systemd/system/vncserver@:1.service

Replace the string <USER> with appropriate vncuser’s username.  In my case I will be using the user srijan just created above:

[...]
[Service] Type=forking # Clean any existing files in /tmp/.X11-unix environment ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' #ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i" #PIDFile=/home/<USER>/.vnc/%H%i.pid ExecStart=/sbin/runuser -l srijan -c "/usr/bin/vncserver %i" PIDFile=/home/srijan/.vnc/%H%i.pid ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

If you wish to add more users you would create a new vncserver@:#.service file and change the <USER> string to the new users.

Firewall settings:

firewall-cmd --permanent --zone=public --add-service vnc-server
firewall-cmd --reload

Now switch to the vncuser just created above and start the vnc service as:

su - srijan
vncserver

[[email protected] ~]$ vncserver

You will require a password to access your desktops.

Password:<--yourvncpassword
Verify:<--yourvncpassword
xauth:  file /home/srijan/.Xauthority does not exist

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

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

[[email protected] ~]$

Now make the service enabled on after every reboot with root credentials:

su -
systemctl daemon-reload

systemctl enable vncserver@:1.service

reboot
systemctl start vncserver@:1.service

4 VNC Client

At client end my OS is Ubuntu 14.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.

Now I am going to connect with the VNC server through my VNC-client at 192.168.0.100:5901

It will prompt for the password, give the vnc password just created above as follows:

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




Now you are connected with the CentOS 7.0 Server. In case you want to add more users to access the vnc-console you need to add :

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service
vi /etc/systemd/system/vncserver@:2.service

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

[...]
[Service] Type=forking # Clean any existing files in /tmp/.X11-unix environment ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' #ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i" #PIDFile=/home/<USER>/.vnc/%H%i.pid ExecStart=/sbin/runuser -l kishore -c "/usr/bin/vncserver %i" PIDFile=/home/kishore/.vnc/%H%i.pid ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

Now switch to the vncuser just created above and start the vnc service as:

su - kishore
vncserver

[[email protected] ~]$ vncserver

You will require a password to access your desktops.

Password:<--yourvncpassword
Verify:<--yourvncpassword
xauth:  file /home/kishore/.Xauthority does not exist

New 'server1.example.com:2 (kishore)' desktop is server1.example.com:2

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

[[email protected] ~]$

Now  start the service on after every reboot for second user as follows:

systemctl daemon-reload

systemctl enable vncserver@:2.service

reboot
systemctl start vncserver@:2.service

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

Congrats you have configured the VNC-server in CentOS 7.0 successfully :) 
Share this page:

24 Comment(s)

Add comment

Comments

From: Scott Dowdle

In the EPEL repository for EL7 x2go is available.  x2goserver and x2goclient are basically a fork of No Machine's NX3 protocol and is much faster and more flexible than VNC.  x2go also uses ssh for transport so no additional ports need to be open.  x2go also includes sound support.  Give it a try.  About the only thing you can't do with x2go is 3D stuff... so desktop environments that require accelerated 3D support won't work.

From: Johnny

Hi

 Thank a lot for this great tutorial. It really works ! very great i must say, over Gnome desktop.

 But i try it for xfce desktop, but it just give me error at login when i log. I can log ok with vnc, but login screen said : ops error and click for logout. after that, just the vnc pointer and the black screen.

 Is there's other setting to add to have vnc run with XFCE ?

Thanks

From: Diego

I did all but i got error:

Timed out waiting for a response from the host computer

The logfile: 

GNU nano 2.3.1 File: ...joe/.vnc/ns500529.ip-192-99-1.net:1.log


Initializing built-in extension MIT-SCREEN-SAVER

Initializing built-in extension DOUBLE-BUFFER

Initializing built-in extension RECORD

Initializing built-in extension DPMS

Initializing built-in extension X-Resource

Initializing built-in extension XVideo

Initializing built-in extension XVideo-MotionCompensation

Initializing built-in extension VNC-EXTENSION

Initializing built-in extension GLX


Sat Dec  6 16:14:37 2014

 vncext:      VNC extension running!

 vncext:      Listening for VNC connections on all interface(s), port 5901

 vncext:      created VNC server for screen 0

...

 How to fix it, please??

 Thank you!

From: Dan Kirk

Very good tutorial and worked very well Thank you very much

From: Danyal

Hey

 great work!!

From: cperera

Great tutorial, it worked for me. Thank you for taking time to post it. 

From: VINAY13

please tell me how i can undo the steps after editing the VNC,this is because i missed to swith to the new user name replaced in the VNC file <user> changed it to root as one a my friend told me though he wasn't sure it would work i tried it.but after that i missed out on the step to switch to the newly added user in my case root.every thing else after wards went fine but i couldn't connect to the vps through rermote access . i had difficulties editing the vnc file as i was not quit used to vi editior.

i gave it a second attempt,again copied the VNC file and tried diffrent names and such but the output asking to set the new password wouldn't come after the first attempt

this is what happens :

[[email protected]~]# vncserver

New 'vinay:4 (root)' desktop is vinay:4

starting aplications specified in /root/.vnc/xstartup

Log file is /root/.vnc/vinay:4.log

[[email protected] ~]#

From: ct

I used Safari and the Screen Sharing .app but I get a "Connection failed to 192.168.1.40:5901. The software on the remote computer appears to be incompatible with this version of Screen Sharing."  Thoughts on what could be the culprit?

From: David Griffis

Thanks.  Worked right off the bat.  Very nice!

From: David Griffis

When you turn off your server you have to perform the following steps to restart services.

1. under the created user enter 'vncserver'

2. su -

and then enter:

vncserver@:1service

(or if you created 2 then enter 2)

3. now enter vnc://<IP>:5901 into safari  and you can login

Trying to figure out an automated way to have these 2 service load

From: Ross

Great tutorial - wish I had come here first.  Thanks for the post.

From: Paul Threadgold

Thanks, worked like a charm.. I've used it several times now..

From: Eric

Seriously helpful.  Used this to get it working in Scientific Linux.  Thanks.

From: Pankaj Kumar

It works in first attempt. The change of file path was creating confusion.

Thank you so much.

From: MP

nice tutorial, thanks,

But i see a new session not "my session", what i do wrong?

Cheers,

From: Muralidhar

Nice tutorial, it worked for me

From: Vitor Jr.

It worked like a charm! :)

 

There is a way to change de default resolution and depth?

 

Regards

Vitor Jr.

From: arun

Thanks for this tutorial...

I have one doubt, using this following installation i will communicate all systems but Centos 7 pc will not communicate to Centos 6.4 pc..

centos 6.4 pc will access to communicate centos 7..please kindly solve my problem

From: Gustavo

Excellent, but i did a second vnc screen for the oracle user and i cant connect to that one, the root one connects normally, but the second one is just giving me connection refused.

From: Sado

Can you name a single CentOS GUI tool that make the administration more powerful compared to CLI?

From: skpete

 

can someone please explaind on how to carry this out step by step it wont let me save it its very frustrating

 

Replace the string <USER> with appropriate vncuser’s username.  In my case I will be using the user srijan just created above:

From: Muhammad Aasim

Hi

I followed these steps . 

 

However when i typed reboot just before the vnc client step, my server stopped working. 

I contacted customer support and they said 

"Installation of NetworkManager broke networking on the VM. 

I have removed the package and the issue is now resolved."

What does this actually means.. 

My server started working normally but I was not able to connect with VNC

From: Deepak

What if I want to share a active desktop ? i.e. sharing screen and control.

From: tony

great article and posting it is much appreciated.