Chapter 13. 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.

13.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.

13.1.1. Installing VNC Server

To install the TigerVNC server, issue the following command as root:

~]# yum install tigervnc-server

13.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.

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 13.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.

    ExecStart=/usr/bin/vncserver_wrapper <USER> %i
    Note

    The default size of the VNC desktop is 1024x768.

    A user’s VNC session can be further configured using the ~/.vnc/config file.

    For example, to change the VNC window size, add the following line:

    geometry= <WIDTH> x <HEIGHT>

  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.

Proceed to Section 13.1.3, “Starting VNC Server”.

13.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:

13.1.3. Starting VNC Server

To start or enable the service, specify the display number directly in the command. The file configured above in 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.

13.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

13.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 xinetd packages are installed.

~]# yum install gdm tigervnc tigervnc-server xinetd

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

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

13.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

13.2. Sharing an Existing Desktop

By default a logged in user has a desktop provided by X Server on display 0. A user can share their desktop using the TigerVNC server x0vncserver.

Sharing an X Desktop

To share the desktop of a logged in user, using the x0vncserver, proceed as follows:

  1. Enter the following command as root

    ~]# yum install tigervnc-server
  2. Set the VNC password for the user:

    ~]$ vncpasswd
    Password:
    Verify:
  3. Enter the following command as that user:

    ~]$ x0vncserver -PasswordFile=.vnc/passwd -AlwaysShared=1

Provided the firewall is configured to allow connections to port 5900, the remote viewer can now connect to display 0, and view the logged in users desktop. See Section 13.3.2.1, “Configuring the Firewall for VNC” for information on how to configure the firewall.

13.3. VNC Viewer

vncviewer is a program which shows the graphical user interfaces and controls the vncserver remotely.

For operating the vncviewer, there is a pop-up menu containing entries which perform various actions such as switching in and out of full-screen mode or quitting the viewer. Alternatively, you can operate vncviewer through the terminal. Enter vncviewer -h on the command line to list vncviewer's parameters.

13.3.1. Installing VNC Viewer

To install the TigerVNC client, vncviewer, issue the following command as root:

~]# yum install tigervnc

13.3.2. Connecting to VNC Server

Once the VNC server is configured, you can connect to it from any VNC viewer.

Connecting to a VNC Server Using a GUI

  1. Enter the vncviewer command with no arguments, the VNC Viewer: Connection Details utility appears. It prompts for a VNC server to connect to.
  2. If required, to prevent disconnecting any existing VNC connections to the same display, select the option to allow sharing of the desktop as follows:

    1. Select the Options button.
    2. Select the Misc. tab.
    3. Select the Shared button.
    4. Press OK to return to the main menu.
  3. Enter an address and display number to connect to:

    address:display_number
  4. Press Connect to connect to the VNC server display.
  5. You will be prompted to enter the VNC password. This will be the VNC password for the user corresponding to the display number unless a global default VNC password was set.

    A window appears showing the VNC server desktop. Note that this is not the desktop the normal user sees, it is an Xvnc desktop.

Connecting to a VNC Server Using the CLI

  1. Enter the viewer command with the address and display number as arguments:

    vncviewer address:display_number

    Where address is an IP address or host name.

  2. Authenticate yourself by entering the VNC password. This will be the VNC password for the user corresponding to the display number unless a global default VNC password was set.
  3. A window appears showing the VNC server desktop. Note that this is not the desktop the normal user sees, it is the Xvnc desktop.

13.3.2.1. Configuring the Firewall for VNC

When using a non-encrypted connection, firewalld might block the connection. To allow firewalld to pass the VNC packets, you can open specific ports to TCP traffic. When using the -via option, traffic is redirected over SSH which is enabled by default in firewalld.

Note

The default port of VNC server is 5900. To reach the port through which a remote desktop will be accessible, sum the default port and the user’s assigned display number. For example, for the second display: 2 + 5900 = 5902.

For displays 0 to 3, make use of firewalld's support for the VNC service by means of the service option as described below. Note that for display numbers greater than 3, the corresponding ports will have to be opened specifically as explained in Opening Ports in firewalld.

Enabling VNC Service in firewalld

  1. Run the following command to see the information concerning firewalld settings:

    ~]$ firewall-cmd --list-all
  2. To allow all VNC connections from a specific address, use a command as follows:

    ~]# firewall-cmd --add-rich-rule='rule family="ipv4" source address="192.168.122.116" service name=vnc-server accept'
    success

    Note that these changes will not persist after the next system start. To make permanent changes to the firewall, repeat the commands adding the --permanent option. See the Red Hat Enterprise Linux 7 Security Guide for more information on the use of firewall rich language commands.

  3. To verify the above settings, use a command as follows:

    ~]# firewall-cmd --list-all
    public (default, active)
     interfaces: bond0 bond0.192
     sources:
     services: dhcpv6-client ssh
     ports:
     masquerade: no
     forward-ports:
     icmp-blocks:
     rich rules:
    	rule family="ipv4" source address="192.168.122.116" service name="vnc-server" accept

To open a specific port or range of ports make use of the --add-port option to the firewall-cmd command Line tool. For example, VNC display 4 requires port 5904 to be opened for TCP traffic.

Opening Ports in firewalld

  1. To open a port for TCP traffic in the public zone, issue a command as root as follows:

    ~]# firewall-cmd --zone=public --add-port=5904/tcp
    success
  2. To view the ports that are currently open for the public zone, issue a command as follows:

    ~]# firewall-cmd --zone=public --list-ports
    5904/tcp

A port can be removed using the firewall-cmd --zone=zone --remove-port=number/protocol command.

Note that these changes will not persist after the next system start. To make permanent changes to the firewall, repeat the commands adding the --permanent option. For more information on opening and closing ports in firewalld, see the Red Hat Enterprise Linux 7 Security Guide.

13.3.3. Connecting to VNC Server Using SSH

VNC is a clear text network protocol with no security against possible attacks on the communication. To make the communication secure, you can encrypt your server-client connection by using the -via option. This will create an SSH tunnel between the VNC server and the client.

The format of the command to encrypt a VNC server-client connection is as follows:

vncviewer -via user@host:display_number

Example 13.1. Using the -via Option

  1. To connect to a VNC server using SSH, enter a command as follows:

    ~]$ vncviewer -via USER_2@192.168.2.101:3
  2. When you are prompted to, type the password, and confirm by pressing Enter.
  3. A window with a remote desktop appears on your screen.
Restricting VNC Access

If you prefer only encrypted connections, you can prevent unencrypted connections altogether by using the -localhost option in the systemd.service file, the ExecStart line:

ExecStart=/usr/sbin/runuser -l user -c "/usr/bin/vncserver -localhost %i"

This will stop vncserver from accepting connections from anything but the local host and port-forwarded connections sent using SSH as a result of the -via option.

For more information on using SSH, see Chapter 12, OpenSSH.

13.4. Additional Resources

For more information about TigerVNC, see the resources listed below.

Installed Documentation

  • vncserver(1) — The manual page for the VNC server utility.
  • vncviewer(1) — The manual page for the VNC viewer.
  • vncpasswd(1) — The manual page for the VNC password command.
  • Xvnc(1) — The manual page for the Xvnc server configuration options.
  • x0vncserver(1) — The manual page for the TigerVNC server for sharing existing X servers.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.