Chapter 11. TigerVNC

TigerVNC (Tiger Virtual Network Computing) is a system for graphical desktop sharing which allows you to remotely control other computers.
TigerVNC works on the client-server principle: a server shares its output (vncserver) and a client (vncviewer) connects to the server.

Note

Unlike in previous Red Hat Enterprise Linux distributions, TigerVNC in Red Hat Enterprise Linux 7 uses the systemd system management daemon for its configuration. The /etc/sysconfig/vncserver configuration file has been replaced by /etc/systemd/system/vncserver@.service.

11.1. VNC Server

vncserver is a utility which starts a VNC (Virtual Network Computing) desktop. It runs Xvnc with appropriate options and starts a window manager on the VNC desktop. vncserver allows users to run separate sessions in parallel on a machine which can then be accessed by any number of clients from anywhere.

11.1.1. Installing VNC Server

To install the TigerVNC server, issue the following command as root:
~]# yum install tigervnc-server

11.1.2. Configuring VNC Server

The VNC server can be configured to start a display for one or more users, provided that accounts for the users exist on the system, with optional parameters such as for display settings, network address and port, and security settings.

Procedure 11.1. Configuring a VNC Display for a Single User

  1. A configuration file named /etc/systemd/system/vncserver@.service is required. To create this file, copy the /usr/lib/systemd/system/vncserver@.service file as root:
    ~]# cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service
    There is no need to include the display number in the file name because systemd automatically creates the appropriately named instance in memory on demand, replacing '%i' in the service file by the display number. For a single user it is not necessary to rename the file. For multiple users, a uniquely named service file for each user is required, for example, by adding the user name to the file name in some way. See Section 11.1.2.1, “Configuring VNC Server for Two Users” for details.
  2. Edit /etc/systemd/system/vncserver@.service, replacing USER with the actual user name. Leave the remaining lines of the file unmodified. The -geometry argument specifies the size of the VNC desktop to be created; by default, it is set to 1024x768.
    ExecStart=/usr/sbin/runuser -l USER -c "/usr/bin/vncserver %i -geometry 1280x1024"
    PIDFile=/home/USER/.vnc/%H%i.pid
    
  3. Save the changes.
  4. To make the changes take effect immediately, issue the following command:
    ~]# systemctl daemon-reload
  5. Set the password for the user or users defined in the configuration file. Note that you need to switch from root to USER first.
    ~]# su - USER
    ~]$ vncpasswd
    Password:
    Verify:

    Important

    The stored password is not encrypted; anyone who has access to the password file can find the plain-text password.

11.1.2.1. Configuring VNC Server for Two Users

If you want to configure more than one user on the same machine, create different template-type service files, one for each user.
  1. Create two service files, for example vncserver-USER_1@.service and vncserver-USER_2@.service. In both these files substitute USER with the correct user name.
  2. Set passwords for both users:
    ~]$ su - USER_1
    ~]$ vncpasswd
    Password:
    Verify:
    ~]$ su - USER_2
    ~]$ vncpasswd
    Password:
    Verify:
    

11.1.3. Starting VNC Server

To start or enable the service, specify the display number directly in the command. The file configured above in Procedure 11.1, “Configuring a VNC Display for a Single User” works as a template, in which %i is substituted with the display number by systemd. With a valid display number, execute the following command:
~]# systemctl start vncserver@:display_number.service
You can also enable the service to start automatically at system start. Then, when you log in, vncserver is automatically started. As root, issue a command as follows:
~]# systemctl enable vncserver@:display_number.service
At this point, other users are able to use a VNC viewer program to connect to the VNC server using the display number and password defined. Provided a graphical desktop is installed, an instance of that desktop will be displayed. It will not be the same instance as that currently displayed on the target machine.

11.1.3.1. Configuring VNC Server for Two Users and Two Different Displays

For the two configured VNC servers, vncserver-USER_1@.service and vncserver-USER_2@.service, you can enable different display numbers. For example, the following commands will cause a VNC server for USER_1 to start on display 3, and a VNC server for USER_2 to start on display 5:
~]# systemctl start vncserver-USER_1@:3.service
~]# systemctl start vncserver-USER_2@:5.service

11.1.4. VNC setup based on xinetd with XDMCP for GDM

VNC setup based on xinetd with X Display Manager Control Protocol (XDMCP) for GDM is a useful setup for client systems that consist mainly of thin clients. After the setup, clients are able to access the GDM login window and log in to any system account. The prerequisite for the setup is that the gdm, vnc, vnc-server & and xinet packages are installed.
~]# yum install gdm tigervnc tigervnc-server xinet
Service xinetd must be enabled.
~]# systemctl enable xinetd.service
System default target unit should be graphical.target. To get the currently set default target unit, use:
~]# systemctl get-default
The default target unit can be changed by using:
~]# systemctl set-default target_name

Procedure 11.2. Accessing the GDM login window and logging in

  1. Set up GDM to enable XDMCP by editing the /etc/gdm/custom.conf configuration file:
    [xdmcp]
    Enable=true
    
  2. Create a file called /etc/xinetd.d/xvncserver with the following content:
    service service_name
    {
    disable = no
    protocol = tcp
    socket_type = stream
    wait = no
    user = nobody
    server = /usr/bin/Xvnc
    server_args = -inetd -query localhost -once -geometry selected_geometry -depth selected_depth securitytypes=none
    }
    
    In the server_args section, the -query localhost option will make each Xvnc instance query localhost for an xdmcp session. The -depth option specifies the pixel depth (in bits) of the VNC desktop to be created. Acceptable values are 8, 15, 16 and 24 - any other values are likely to cause unpredictable behavior of applications.
  3. Edit file /etc/services to have the service defined. To do this, append the following snippet to the /etc/services file:
    # VNC xinetd GDM base
    service_name 5950/tcp
    
  4. To ensure that the configuration changes take effect, reboot the machine.
    Alternatively, you can run the following. Change init levels to 3 and back to 5 to force gdm to reload.
    # init 3
    # init 5
    
    Verify that gdm is listening on UDP port 177.
    # netstat -anu|grep 177
    udp        0      0 0.0.0.0:177                 0.0.0.0:*
    
    Restart the xinetd service.
    ~]# systemctl restart xinetd.service
    Verify that the xinetd service has loaded the new services.
    # netstat -anpt|grep 595
    tcp        0      0 :::5950                     :::*                        LISTEN      3119/xinetd
    
  5. Test the setup using a vncviewer command:
    # vncviewer localhost:5950
    
    The command will launch a VNC session to the localhost where no password is asked. You will see a GDM login screen, and you will be able to log in to any user account on the system with a valid user name and password. Then you can run the same test on remote connections.
Configure firewall for the setup. Run the firewall configuration tool and add TCP port 5950 to allow incoming connections to the system.
~]# firewall-cmd --permanent --zone=public --add-port=5950/tcp
~]# firewall-cmd --reload

11.1.5. Terminating a VNC Session

Similarly to enabling the vncserver service, you can disable the automatic start of the service at system start:
~]# systemctl disable vncserver@:display_number.service
Or, when your system is running, you can stop the service by issuing the following command as root:
~]# systemctl stop vncserver@:display_number.service