Install and Configure VNC console in Centos7

Windows Articles

How to update apps on Android

Hi folks! In this post, we will show you how to update your Android apps. Updating the apps on your device is...

How to install Apache Ant on Ubuntu 20.04?

Hello, friends. Apache Ant is a very important tool for the development of applications in Java. So in this post, we will...

How to use the ss command

For Linux users, there will come a time when you need to know about the network. Several tools help in this process,...

How to create user template in Windows Server 2019/2016

Hello! Windows Server has many features that support system administration. For example, through the users it is possible to manage many administrative...

Debian 10.6 available

Several volunteers have developed the free software distributed under the name of Debian. Debian does not sell its software directly, the developers...
Muhammad Nabeel
Muhammad Nabeel
Network and System Administrator

In this article you will learn how to install and configure VNC in Centos and RHEL

VNC (Virtual Network Computing) is a protocol which is used to remotely access user accounts by the Graphical User Interface.

Step 1: Install VNC

You need to use following command in order to install VNC. Makse sure you are login as root user.

# yum install tigervnc-server -y

Step 2: Setup VNC Password

After installation, login with the user you want to allow VNC remote access and and set VNC password for that user. I will enable VNC access to root user.

 

# su - user_name

# vncpasswd

Step 3: VNC Configuration

Now create a VNC file for your user. I template file vncserver@.service placed in below mentioned path, we will use copy of that file and make configuration for VNC user.

/lib/systemd/system/vncserver@.service

Use following command to make copy of vncserver@.service file.
Note: New file will be named as vncserver@:1.service

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

 

Number 1 after @ sign represents the display number (port 5900+display). Secondly the port 5900 will be incremented by 1 with each started VNC server.

Now edit vncserver@:1.service file using following command.

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

and add the below lines in this file. Replace your_user with your username.

[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=/usr/sbin/runuser -l your_user -c "/usr/bin/vncserver %i
PIDFile=/home/You_user/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

save changes to file and quite

Step 4: Reload Necessary Daemons

After changes in file, reload systemd program to load new VNC configuration file and start the VNC server. Use following commands

# systemctl daemon-reload

# systemctl start vncserver@:1

# systemctl status vncserver@:1

# systemctl enable vncserver@:1

Step 5: Add Ports in Firewall

You must add VNC open ports in firewall so VNC client can access the system.
Use below command to list listening ports of VNC server

# ss -tulpn| grep vnc

Note: If you started multiple VNC instances for different users, the port value will be 5902 for the second, 5903 for the third and so on.

Use followings commands to add ports and reload firewall.

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

# firewall-cmd --reload

Step 6: Connect to CentOS Desktop from VNC Client

In order to access Centos desktop you need to install a VNC Client program, then run VNC Client and add the IP address and port number of CentOS VNC server and press enter button.

After that a warning will be displayed, click on continue button and enter VNC password on new screen.

Congratulations! You have access your Centos Desktop from VNC.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to update apps on Android

Hi folks! In this post, we will show you how to update your Android apps. Updating the apps on your device is...

How to install Apache Ant on Ubuntu 20.04?

Hello, friends. Apache Ant is a very important tool for the development of applications in Java. So in this post, we will...

How to use the ss command

For Linux users, there will come a time when you need to know about the network. Several tools help in this process,...

How to create user template in Windows Server 2019/2016

Hello! Windows Server has many features that support system administration. For example, through the users it is possible to manage many administrative...

Debian 10.6 available

Several volunteers have developed the free software distributed under the name of Debian. Debian does not sell its software directly, the developers...