Installing and Configuring a VNC Server on CentOS and RHEL

Posted on the 12 May 2023 by Top10

VNC (Virtual Network Computing) Server is software that allows you to remotely control a computer over a network. With it, the user can go to another computer and perform any action on it as if he were sitting in front of it. VNC Server is used for remote access to computers, server management, and even for training. In this article, we will look at how to set up and use VNC Server on various operating systems.

Unlike other available VNC servers that connect directly to the desktop, such as VNC X or Vino, tigervnc-vncserver uses a different mechanism that sets up a separate virtual desktop for each user.

Step 1: Installing and configuring VNC on CentOS

1. Tigervnc-server is a program that runs an Xvnc server and runs parallel sessions of Gnome or other desktop environments on a VNC desktop.

A running VNC session can be accessed by the same user from multiple VNC clients. To install TigerVNC server on CentOS/RHEL, open a terminal session and run the following yum command as root.

$ sudo yum install tigervnc-server

2. After installing the program, log in as the user you want to run the VNC program as and run the following command in the terminal to set the password for the VNC server.

Remember that the password must be at least six characters long.

$ su - your_user
$ vncpasswd

3. Next, add the VNC service configuration file for your user via the daemon configuration file located in the systemd directory tree. To copy the VNC template file, you need to run the following cp command with root privileges.

If your user does not have sudo privileges, either switch directly to the root account or run the command from an account with root privileges.

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

4. In the next step, edit the copied VNC template configuration file from the /etc/systemd/system/ directory and replace the following values ​​to reflect your user as shown in the example below.

The value 1 after the @ sign is the display number (port 5900+display). Also, for each running VNC server, port 5900 will increase by 1.

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

Add the following lines to the vncserver@:1.service file.

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
 
[Service]
Type=forking
User=tecmint
Group=tecmint
WorkingDirectory=/home/tecmint
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver %i -geometry 1280x1024
PIDFile=/home/tecmint/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' 

[Install]
WantedBy=multi-user.target

5. After making the appropriate changes to the VNC service file, reload the systemd system init program to pick up the new vnc configuration file and start the TigerVNC server.

Also check the status of the VNC service and enable the VNC daemon system wide by running the following commands.

# systemctl daemon-reload
# systemctl start vncserver@:1
# systemctl status vncserver@:1
# systemctl enable vncserver@:1

6. To list the open listening ports owned by the VNC server, run the ss command, which is used to display network sockets. Because you've only started one instance of the VNC server, the first open port is 5901/TCP.

Again, the ss command must be executed with root privileges. If you run other VNC instances in parallel for different users, the port value will be 5902 for the second one, 5903 for the third one, and so on. Ports 6000+ are used to allow X applications to connect to the VNC server.

# ss -tulpn| grep vnc

7. In order for external VNC clients to connect to the VNC server, you must ensure that the appropriate open VNC ports are allowed through your firewall.

If only one VNC server instance is running, only the first dedicated VNC port: 5901/TCP needs to be opened by running the following commands to apply the firewall configuration at run time.

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

Step 2: Connecting to a CentOS Desktop with a VNC Client

8. Being a platform-independent protocol, GUI remote VNC connections can be made from virtually any operating system with a GUI and a dedicated VNC client.

A popular VNC client used on Microsoft-based operating systems and fully compatible with the Linux TigerVNC server is the RealVNC VNC Viewer.

To connect to CentOS Desktop remotely from Microsoft OS via VNC protocol, open the VNC Viewer program, enter the IP address and port number of the CentOS VNC server and press the key [enter].

After establishing a VNC connection, a warning will appear on the screen that the connection is not encrypted, as shown in the screenshots below.

9. To bypass the warning, click Continue, add the password set for the VNC server in step 2, and you should be remotely connected to CentOS Desktop with a user configured to run the VNC server instance.

10. If a new authentication message appears on the screen and the user is not root, simply click the Cancel button to continue working with CentOS Desktop, as shown in the screenshot below.

Keep in mind that the established VNC connection between the server and the client and the exchange of any data (except for the password) takes place over an unencrypted channel. To encrypt and secure VPN communications, you first need to set up a secure SSH tunnel and run any subsequent VPN traffic through the SSH tunnel.

11. To remotely connect to a CentOS desktop via VNC from other CentOS desktops, first make sure the vinagre package is installed on your system by running the following command.

$ sudo yum install vinagre

12. To open the vinagre utility, go to Applications -> Utilities -> Remote Desktop Viewer as shown in the screenshot below.

13. To connect remotely to the CentOS desktop, click the Connect button, select the VNC protocol from the list, and add the IP address and port (5900+display number) of the remote VNC server. Also provide a password for the VNC user as shown in the following screenshots.



14. Another popular VNC client for Linux-based platforms is Remmina, a remote desktop client that is particularly used on Debian-based distributions running the GNOME desktop environment.

To install the Remmina Remote Desktop client on Debian based distributions, run the following command.

$ sudo apt-get install remmina

Step 3Set Up Multiple VNC Sessions on CentOS

15. If you need to start a new parallel VNC session under the same user, open the Terminal console, log in as the user you want to start a new VNC session under, and run the following command.

The first time you start the server, you will be prompted to enter a new password for this session. However, keep in mind that this session is started with the rights of your logged in user and independent of the running systemd VNC server session.

$ vncserver

16. New VNC sessions will open the next available VNC based ports (5900+3 in this example). To display open ports, run the ss command without root privileges, as shown in the following passage. Only running VNC sessions owned by your user will be listed in the list.

$ ss -tlpn| grep Xvnc

17. Now connect remotely to CentOS Desktop using a new VNC session and enter the IP:port (192.168.1.23:5903) combination in the VNC client as shown in the figure below.

To stop the VNC server instances running as these logged in users, run the following command without root privileges. This command will kill all running VNC instances owned only by the user who started them.

$ su - your_user
$ killall Xvnc

That's all! You can now access your CentOS system and perform administrative tasks using the GUI provided by the operating system.

2801200cookie-checkInstalling and configuring a VNC server on CentOS and RHELno

similar

Программы,Рабочее окружение,centos,RHEL,vnc
#Installing #configuring #VNC #server #CentOS #RHEL