Setup VNC-Server Centos 7

This guide is for installing and setting up a VNC-Server on the servers installed with Centos 7. 

1. Log in to the server as root

2. Run the following commands:

yum update -y
yum groupinstall "GNOME Desktop" -y
yum install tigervnc-server -y

3. Once the above packages are fully installed, we need to add a normal user for using VNC

useradd jack

You need to use your own username here.

4. In CentOS 7 OS there is a change in the vncserver configuration file and its location. In Centos 6 OS, it was  /etc/sysconfig/vncservers and now it has been changed to /lib/systemd/system/vncserver@.service. Next, we need to copy the original file and create a new configuration file as shown below:

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

5. Edit the file as below:

vi /etc/systemd/system/vncserver@:1.service
Remember to replace the username with your own.

[...]
[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 jack -c "/usr/bin/vncserver %i" #PIDFile=/home/<USER>/.vnc/%H%i.pid ExecStart=/sbin/runuser -l jack -c "/usr/bin/vncserver %i" PIDFile=/home/jack/.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 can simply create a new user and then add a new vncserver@:#.service file and change the <USER> string to the new users accordingly.

6. Do the following firewall settings:

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

7. Switch to the VNC user and start the vnc server as below:

su - jack
# vncserver

You will get a result as below:

[jack@server1 ~]$ vncserver

You will require a password to access your desktops.

Password:<--yourvncpassword
Verify:<--yourvncpassword

Provide a password for VNC.

8. 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

Now you are done with the server side setup and you will be able to connect to the server with the default port 5901.
eg: 192.168.1.17:5901

Provide the VNC username and password to access the same. 
  •  
  • 150 Users Found This Useful
Was this answer helpful?

Related Articles

How To Install and Use Docker on Ubuntu 16.04

Introduction Docker is an application that makes it simple and easy to run application processes...

Backup and Restore cPanel Accounts via SSH

a. How to create a backup of a cPanel Account via SSH?   1. Log-in to the SSH as the Root...

Change Main IP of the server :: Vesta Panel

If we are changing the main IP of a server installed with Vesta panel, we can use the following...

Change permissions using find command

On a Linux server, if you are in need of changing the permissions of a bulk amount of files or...

Change the time of your vps/dedi

It's very easy, you first need to remove the current time file rm /etc/localtime and replace it...