6 C
Texas
Muhammad Nabeel
Network and System Administrator

Install and Configure VNC console in Centos7

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
- Advertisement -

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 [email protected] placed in below mentioned path, we will use copy of that file and make configuration for VNC user.

/lib/systemd/system/[email protected]

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

# cp /lib/systemd/system/[email protected]   /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.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article