How to install VNC server on Centos 7.3

Installing VNC server on Centos 7.3

VNC is used to connect and control desktop environment of the server from remote clients. VNC viewer is used on remote computer to connect the server .
In this article, we are going to see how to install vnc server on centos 7.3. We can use the default packages provided in the centos yum repository.

Let’s go ahead,

Prerequisites

  • CentOS 7.3 (Operating system used here)
  • root privileges.

Step 1 : Lets start by ensuring our server is up to date.

# yum clean all
# yum -y update

Once updates are completed, reboot the server

Step 2 : If you don’t have desktop environment (X windows), issue the below commands one by one for installing the basic needs.

[root@webhostingchennai ~]# yum groupinstall "GNOME Desktop"
[root@webhostingchennai ~]# yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts
[root@webhostingchennai ~]# unlink /etc/systemd/system/default.target
[root@webhostingchennai ~]# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

Now, reboot the server once again

[root@webhostingchennai ~]# reboot

After reboot, you will get Centos 7.3 desktop.

Step 3 : Now, we can start installing VNC packages.

[root@webhostingchennai ~]# yum install tigervnc-server -y

After installing the VNC packages,  we need to create a file vncserver@:1.service in /etc/systemd/system/ folder by copying the example config file vncserver@.service  in /lib/systemd/system/

[root@webhostingchennai ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

Step 4 : Let add a user for VNC

[root@webhostingchennai ~]# useradd webhostchennai

Step 5 : Now, open vncserver@:1.service file and replace the <USER> with your username.

[root@webhostingchennai ~]# nano /etc/systemd/system/vncserver@:1.service

Modify the configuration file as below

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[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 webhostchennai -c "/usr/bin/vncserver %i"
PIDFile=/home/webhostchennai/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target

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

Configuring the Firewall

Enable the firewall service

[root@webhostingchennai ~]# systemctl enable firewalld
[root@webhostingchennai ~]# systemctl start firewalld
[root@webhostingchennai ~]# firewall-cmd --permanent --add-service vnc-server
[root@webhostingchennai ~]# firewall-cmd --permanent --zone=public --add-port=5905/tcp
[root@webhostingchennai ~]# firewall-cmd --reload

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

[root@webhostingchennai ~] su - webhostchennai
[webhostchennai@webhostingchennai ~]$ vncserver

 

Step 6 :  Now create VNC password for the user.

[root@webhostingchennai ~]# vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
Verify:
[root@webhostingchennai ~]#

Step 7 :  Enable and start the service.

[root@webhostingchennai ~]# systemctl enable vncserver@:1.service

Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:1.service to /etc/systemd/system/vncserver@:1.service.
[root@webhostingchennai ~]# systemctl start vncserver@:1.service

Now we can able to connect VNC server using IP and Port using VNC viewer application.

Before connecting, Make sure the port 5901 is enabled in your local firewall  (if you are using) and your ISP end.

installing vnc server on centos

 

installing vnc server on centos

Additional Commands:

To stop VNC service

[root@webhostingchennai ~]# systemctl stop vncserver@:1.service

To disable VNC service from startup

[root@webhostingchennai ~]# systemctl disable vncserver@:1.service

To stop firewall

[root@webhostingchennai ~]# systemctl stop firewalld.service


You may also like...