How to Install VNC Server on CentOS 7

In this article, we will have explained the necessary steps to install and configure VNC Server on CentOS 7. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

VNC (Virtual Network Computing) is a Server-client protocol, which allows user accounts to connect and control a remote platform supplied by the Graphical User Interface.

Install VNC Server on CentOS 7

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo yum install epel-release
sudo yum update

Step 2. Install Gnome desktop.

Before installing the VNC server, you would need install Gnome desktop using YUM command:

yum groupinstall "GNOME Desktop"

Step 3. Installing VNC Server.

Type the following command to install TigerVNC on your CentOS server:

yum install tigervnc-server xorg-x11-fonts-Type1

Step 4. Configure VNC Server.

First, add a VNC service configuration file for your user via a daemon configuration file placed in systemd directory tree:

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

Next step edit the copied VNC template configuration file from /etc/systemd/system/ directory and replace the values to reflect your user as shown in the below sample:

nano /etc/systemd/system/[email protected]\:1.service

Add the following lines to file file [email protected]:1.service:

Description=Remote desktop service (VNC)

ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l user -c "/usr/bin/vncserver %i -geometry 1280x1024"
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'


After you’ve made the proper changes to VNC service file, reload systemd system initialization program to pick up the new vnc configuration file and start the TigerVNC server:

systemctl daemon-reload
systemctl start [email protected]:1
systemctl status [email protected]:1
systemctl enable [email protected]:1

Step 5. Set the Firewall Rule if firewall is enabled on your Linux server.

In case just one instance of VNC server is started, you only need to open the first allocated VNC port: 5901/TCP by issuing the below commands to apply the firewall configuration at runtime:

firewall-cmd --add-port=5901/tcp
firewall-cmd --add-port=5901/tcp --permanent

Step 6. Connecting to CentOS Desktop via VNC Client.

In this example we’ll be using TigerVNC. Open your VNC viewer, enter localhost:5901 and click on the Connect button.

Install VNC Server on CentOS 7

Congratulation, you have learned how to install and configure VNC server on CentOS 7. If you have any question, please leave a comment below.