How to Install and Configure VNC Server in CentOS 7


2018-10-26 03:07
zpq
16

In this guide we’ll explain how to install and configureVNC Remote Access in latest release of CentOS 7 and RHEL 7 Desktop edition via tigervnc-server program.

VNC (Virtual Network Computing) is a server-client protocol which allows user accounts to remotely connect and control a distant system by using the resources provided by the Graphical User Interface.

Unlike other VNC servers available which connects directly to the runtime desktop, such as VNC X or Vino, tigervnc-vncserver uses a different mechanism that configures a standalone virtual desktop for each user.

Install and Configure VNC in CentOS 7

  1. Tigervnc-server is a program which executes an Xvnc server and starts parallel sessions of Gnome or other Desktop Environment on the VNC desktop.
    A started VNC user session can be accessed by same user from multiple VNC clients. In order to install TigerVNC server in CentOS 7, open a Terminal session and issue the following command with root privileges.
# yum install tigervnc-server
  1. After, you’ve installed the program, login with the user you want to run the VNC program and issue the below command in terminal in order to configure a password for the VNC server.
    Be aware that the password must be at least six characters length.
$ su - your_user  # If you want to configure VNC server to run under this user directly from CLI without switching users from GUI
$ vncpasswd
  1. Next, add a VNC service configuration file for your user via a daemon configuration file placed in systemd directory tree. In order to copy the VNC template file you need to run the following command with root privileges.
    If your user is not granted with sudo privileges, either switch directly to root account or run the command from an account with root privileges.
# cp /lib/systemd/system/[email protected]  /etc/systemd/system/[email protected]:1.service
  1. On the 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.
    The value of 1 after @ sign represents the display number (port 5900+display). Also, for each started VNC server, the port 5900 will be incremented by 1.
# vi /etc/systemd/system/[email protected]\:1.service

-#-more-#-

Edit

[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 <USER> -c "/usr/bin/vncserver %i -geometry 1280x1024"
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target
  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.
    Also, check VNC service status and enable the VNC daemon system-wide by issuing the below commands.
# systemctl daemon-reload
# systemctl start [email protected]:1
# systemctl status [email protected]:1
# systemctl enable [email protected]:1

Start-VNC-Service.png

  1. To list the opened ports in listening state owned by the VNC server, run the ss command, which is used in CentOS 7 to display network sockets. Because you’ve only started one instance of VNC server, the first open port is 5901/TCP.
    Again, the ss command must be executed with root privileges. In case you start other VNC instances in parallel for different users, the port value will be 5902 for the second, 5903 for the third and so on. The ports** 6000+** are used for allowing the X applications to connect to the VNC server.
# ss -tulpn| grep vnc

Verify-VNC-Listening-Ports.png

  1. In order to allow external VNC clients to connect to the VNC server in CentOS, you need to make sure the proper VNC open ports are allowed to pass through your firewall.
    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

https://www.tecmint.com/install-and-configure-vnc-server-in-centos-7/

声明:本站文章版权归原作者及原出处所有