Configure VNC Server on CentOS 7 and RHEL 7

Dear friends in this tutorial, we will see How to install and configure VNC Server on CentOS 7 and RHEL 7. So let’s start step by step.

VNC ( Virtual Network Computing ), VNC Server is used to take remote access of Linux machine, Such as MSTSC in windows. It is also known as RFB or Remote Frame Buffer. In this tutorial we will see how to install and configure VNC server on Linux machine and how to install and configure VNC viewer on Windows machine. So let’s start and see step by steps installation and configuration of VNC server and VNC viewer.

Required packages installation

First of all we have to check “Desktop” packages on our Linux server, If Desktop packages are not installed. Then we need to install Desktop packages. If Desktop packages are already installed then we can ignore this steps, and we can go to install VNC server packages.

[[email protected] ~]# yum groupinstall "Desktop" yum groupinstall "GNOME Desktop"

Install VNC Server on Linux Machine

Now we need to install VNC server package in our Linux machine. We can use below command to install VNC server in our Linux machine.

[[email protected] ~]# yum install vnc-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.myfahim.com
* epel: ftp.jaist.ac.jp
* extras: mirrors.vhost.vn
* ius: dfw.mirror.rackspace.com
* updates: mirrors.123host.vn
Resolving Dependencies
--> Running transaction check
---> Package tigervnc-server.x86_64 0:1.8.0-5.el7 will be installed
--> Processing Dependency: tigervnc-server-minimal for package: tigervnc-server-1.8.0-5.el7.x86_64
--> Running transaction check
---> Package tigervnc-server-minimal.x86_64 0:1.8.0-5.el7 will be installed
--> Processing Dependency: tigervnc-license for package: tigervnc-server-minimal-1.8.0-5.el7.x86_64
--> Running transaction check
---> Package tigervnc-license.noarch 0:1.8.0-5.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================================================
Installing:
tigervnc-server x86_64 1.8.0-5.el7 base 214 k
Installing for dependencies:
tigervnc-license noarch 1.8.0-5.el7 base 28 k
tigervnc-server-minimal x86_64 1.8.0-5.el7 base 1.0 M

Transaction Summary
========================================================================================================================================================================
Install 1 Package (+2 Dependent packages)

Total download size: 1.3 M
Installed size: 3.0 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): tigervnc-license-1.8.0-5.el7.noarch.rpm | 28 kB 00:00:00
(2/3): tigervnc-server-1.8.0-5.el7.x86_64.rpm | 214 kB 00:00:03
(3/3): tigervnc-server-minimal-1.8.0-5.el7.x86_64.rpm | 1.0 MB 00:00:04
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 257 kB/s | 1.3 MB 00:00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tigervnc-license-1.8.0-5.el7.noarch 1/3
Installing : tigervnc-server-minimal-1.8.0-5.el7.x86_64 2/3
Installing : tigervnc-server-1.8.0-5.el7.x86_64 3/3
Verifying : tigervnc-license-1.8.0-5.el7.noarch 1/3
Verifying : tigervnc-server-minimal-1.8.0-5.el7.x86_64 2/3
Verifying : tigervnc-server-1.8.0-5.el7.x86_64 3/3

Installed:
tigervnc-server.x86_64 0:1.8.0-5.el7

Dependency Installed:
tigervnc-license.noarch 0:1.8.0-5.el7 tigervnc-server-minimal.x86_64 0:1.8.0-5.el7

Complete!
[[email protected] ~]#

You will see in above tigervnc-server package is successfully installed in CentOS7.

Now we need to Create User for VNC

HostGator Web Hosting
Here I am going to creating one user to connect through VNC viewer. We can also use our existing users to connect through VNC viewer. If we are using existing user then we need to set vncpasswd for this user, so that we can connect this user with VNC viewer.

[[email protected] ~]# useradd test1
[[email protected] ~]# passwd test1
Changing password for user test1.
New password:
BAD PASSWORD: The password fails the dictionary check - it is too simplistic/systematic
Retype new password:
passwd: all authentication tokens updated successfully.
[[email protected] ~]#

Now we need to set the VNC password for account test1 to connect through VNC.

[[email protected] ~]# su - test1
[[email protected] ~]$ pwd
/home/test1
[[email protected] ~]$
[[email protected] ~]$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
Verify:
[[email protected] ~]$
[[email protected] ~]$ exit
logout
[[email protected] ~]#

VNC Server configuration for Users

First of all copy [email protected] in [email protected]:1.server

[[email protected] ~]# cp /lib/systemd/system/[email protected] /etc/systemd/system/[email protected]:1.service

After that We need to configured /etc/systemd/system/[email protected]:1.service file and add this line end of the file. Make sure your user and user path should be correctly enter in this file. You can see in bold of user entry in this file. Like that:-

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l test1 -c "/usr/bin/vncserver %i -geometry 1280x1024"
PIDFile=/home/test1/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target`

After this configuration, now we can start VNC service using below command.

[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl start [email protected]:1
[[email protected] ~]# systemctl status [email protected]:1
● [email protected]:1.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/[email protected]:1.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2018-06-24 12:53:41 CEST; 13s ago
Process: 4636 ExecStart=/sbin/runuser -l test1 -c /usr/bin/vncserver %i -geometry 1280x1024 (code=exited, status=0/SUCCESS)
Process: 4633 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Main PID: 4661 (Xvnc)
CGroup: /system.slice/system-vncserver.slice/[email protected]:1.service
‣ 4661 /usr/bin/Xvnc :1 -auth /home/test1/.Xauthority -desktop dns.tzclouds.local:1 (test1) -fp catalogue:/etc/X11/fontpath.d -geometry 1280x1024 -pn -rfb...

Jun 24 12:53:37 dns.tzclouds.local systemd[1]: Starting Remote desktop service (VNC)...
Jun 24 12:53:41 dns.tzclouds.local systemd[1]: Started Remote desktop service (VNC).
[[email protected] ~]# systemctl status [email protected]:1
● [email protected]:1.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/[email protected]:1.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2018-06-24 12:53:41 CEST; 20s ago
Process: 4636 ExecStart=/sbin/runuser -l test1 -c /usr/bin/vncserver %i -geometry 1280x1024 (code=exited, status=0/SUCCESS)
Process: 4633 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Main PID: 4661 (Xvnc)
CGroup: /system.slice/system-vncserver.slice/[email protected]:1.service
‣ 4661 /usr/bin/Xvnc :1 -auth /home/test1/.Xauthority -desktop dns.tzclouds.local:1 (test1) -fp catalogue:/etc/X11/fontpath.d -geometry 1280x1024 -pn -rfb...

Jun 24 12:53:37 dns.tzclouds.local systemd[1]: Starting Remote desktop service (VNC)...
Jun 24 12:53:41 dns.tzclouds.local systemd[1]: Started Remote desktop service (VNC).
[[email protected] ~]#
[[email protected] ~]# systemctl enable [email protected]:1
Created symlink from /etc/systemd/system/multi-user.target.wants/[email protected]:1.service to /etc/systemd/system/[email protected]:1.service.
[[email protected] ~]#

Now we can see above  our VNC service has been successfully enable and started.

We can use ss command to list open ports of VNC server.

[[email protected] ~]# ss -tulpn| grep vnc
tcp LISTEN 0 5 *:5901 *:* users:(("Xvnc",pid=4661,fd=9))
tcp LISTEN 0 128 *:6001 *:* users:(("Xvnc",pid=4661,fd=6))
tcp LISTEN 0 5 :::5901 :::* users:(("Xvnc",pid=4661,fd=10))
tcp LISTEN 0 128 :::6001 :::* users:(("Xvnc",pid=4661,fd=5))
[[email protected] ~]#

VNC port enable

We need to allow port 5901 on server side for external VNC client to connect the VNC server. So let’s start open port from our server side.

[[email protected] ~]# firewall-cmd --add-port=5901/tcp
success
[[email protected] ~]# firewall-cmd --add-port=5901/tcp --permanent
success
[[email protected] ~]#

Connecting VNC Server using VNC Viewer

First of all you have to download VNC viewer for Windows from below link. After that you have install VNC viewer. Then open VNC viewer, and enter VNC server IP and port like below screen shot:-

VNC server IP 192.168.34.95 and VNC port is 5901, and click continue then you can find user password windows like below:-

After password entry you will connect successfully Linux Machine using VNC viewer. You can see below screen shot.

You can see here we have successfully connected our CentOS7 machine using VNC viewer.

That’s all, We have successfully installed and configured VNC server and VNC viewer.

 

4 thoughts on “Configure VNC Server on CentOS 7 and RHEL 7

Leave a Reply

Your email address will not be published. Required fields are marked *