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 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 : 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 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 : 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. Edit /etc/systemd/system/vncserver@.service and in the following line, located in the [Services] section, replace USER with the user name for whom you want to set the VNC server. Leave the remaining lines of the file unmodified. 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> Save the changes. To make the changes take effect immediately, issue the following command: Set the password for the user or users defined in the configuration file. Note that you need to switch from root to USER first. 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. 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. Set passwords for both users: 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: 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: 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: 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. Service xinetd must be enabled. System default target unit should be graphical.target . To get the currently set default target unit, use: The default target unit can be changed by using: Accessing the GDM login window and logging in Set up GDM to enable XDMCP by editing the /etc/gdm/custom.conf configuration file: Create a file called /etc/xinetd.d/xvncserver with the following content: 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. Edit file /etc/services to have the service defined. To do this, append the following snippet to the /etc/services file: 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. Verify that gdm is listening on UDP port 177. Restart the xinetd service. Verify that the xinetd service has loaded the new services. Test the setup using a vncviewer command: 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. 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: Or, when your system is running, you can stop the service by issuing the following command as root : 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: Enter the following command as root Set the VNC password for the user: Enter the following command as that user: 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 : 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 Enter the vncviewer command with no arguments, the VNC Viewer: Connection Details utility appears. It prompts for a VNC server to connect to. If required, to prevent disconnecting any existing VNC connections to the same display, select the option to allow sharing of the desktop as follows: Select the Options button. Select the Misc. tab. Select the Shared button. Press OK to return to the main menu. Enter an address and display number to connect to: Press Connect to connect to the VNC server display. 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 Enter the viewer command with the address and display number as arguments: Where address is an IP address or host name. 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. 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 Run the following command to see the information concerning firewalld settings: To allow all VNC connections from a specific address, use a command as follows: Note that these changes will not persist after the 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. To verify the above settings, use a command as follows: 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 To open a port for TCP traffic in the public zone, issue a command as root as follows: To view the ports that are currently open for the public zone, issue a command as follows: 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 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: Example 13.1. Using the -via Option To connect to a VNC server using SSH , enter a command as follows: When you are prompted to, type the password, and confirm by pressing Enter . 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: 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.

Commands:
~]# yum install tigervnc-server
~]# cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service
ExecStart=/usr/bin/vncserver_wrapper <USER> %i
~]# systemctl daemon-reload
~]# su - USER ~]USD vncpasswd Password: Verify:
~]USD su - USER_1 ~]USD vncpasswd Password: Verify: ~]USD su - USER_2 ~]USD vncpasswd Password: Verify:
~]# systemctl start vncserver@:display_number.service
~]# systemctl enable vncserver@:display_number.service
~]# systemctl start vncserver-USER_1@:3.service ~]# systemctl start vncserver-USER_2@:5.service
~]# yum install gdm tigervnc tigervnc-server xinetd
~]# systemctl enable xinetd.service
~]# systemctl get-default
~]# systemctl set-default target_name
[xdmcp] Enable=true
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 }
VNC xinetd GDM base service_name 5950/tcp
init 3 init 5
netstat -anu|grep 177 udp 0 0 0.0.0.0:177 0.0.0.0:*
~]# systemctl restart xinetd.service
netstat -anpt|grep 595 tcp 0 0 :::5950 :::* LISTEN 3119/xinetd
vncviewer localhost:5950
~]# firewall-cmd --permanent --zone=public --add-port=5950/tcp ~]# firewall-cmd --reload
~]# systemctl disable vncserver@:display_number.service
~]# systemctl stop vncserver@:display_number.service
~]# yum install tigervnc-server
~]USD vncpasswd Password: Verify:
~]USD x0vncserver -PasswordFile=.vnc/passwd -AlwaysShared=1
~]# yum install tigervnc
address : display_number
vncviewer address : display_number
~]USD firewall-cmd --list-all
~]# firewall-cmd --add-rich-rule='rule family="ipv4" source address="192.168.122.116" service name=vnc-server accept' success
~]# 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
~]# firewall-cmd --zone=public --add-port=5904/tcp success
~]# firewall-cmd --zone=public --list-ports 5904/tcp
vncviewer -via user @ host : display_number
~]USD vncviewer -via USER_2@192.168.2.101:3
ExecStart=/usr/sbin/runuser -l user -c "/usr/bin/vncserver -localhost %i"