13.3. VNC Viewer
vncviewer is a program which shows the graphical user interfaces and controls the vncserver remotely.
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
vncviewer, issue the following command as root: ~]# yum install tigervnc
13.3.2. Connecting to VNC Server
Procedure 13.4. Connecting to a VNC Server Using a GUI
- Enter the
vncviewercommand 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 button.
- Select the Misc. tab.
- Select the button.
- Press OK to return to the main menu.
- Enter an address and display number to connect to:
address:display_number
- 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.
Procedure 13.5. Connecting to a VNC Server Using the CLI
- Enter the
viewercommand with the address and display number as arguments:vncviewer address:display_number
Where address is anIPaddress 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
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
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 Procedure 13.7, “Opening Ports in firewalld”.
Procedure 13.6. Enabling VNC Service in firewalld
- Run the following command to see the information concerning
firewalldsettings:~]$firewall-cmd --list-all - To allow all VNC connections from a specific address, use a command as follows:
~]#
Note that these changes will not persist after the next system start. To make permanent changes to the firewall, repeat the commands adding thefirewall-cmd --add-rich-rule='rule family="ipv4" source address="192.168.122.116" service name=vnc-server accept'success--permanentoption. 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:
~]#
firewall-cmd --list-allpublic (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
--add-port option to the firewall-cmd command Line tool. For example, VNC display 4 requires port 5904 to be opened for TCP traffic.
Procedure 13.7. Opening Ports in firewalld
- To open a port for
TCPtraffic in the public zone, issue a command asrootas follows:~]#
firewall-cmd --zone=public --add-port=5904/tcpsuccess - To view the ports that are currently open for the public zone, issue a command as follows:
~]#
firewall-cmd --zone=public --list-ports5904/tcp
firewall-cmd --zone=zone --remove-port=number/protocol command.
--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
-via option. This will create an SSH tunnel between the VNC server and the client.
vncviewer -via user@host:display_number
Example 13.1. Using the -via Option
- To connect to a VNC server using
SSH, enter a command as follows:~]$vncviewer -via USER_2@192.168.2.101:3 - 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
-localhost option in the systemd.service file, the ExecStart line:
ExecStart=/usr/sbin/runuser -l user -c "/usr/bin/vncserver -localhost %i"
vncserver from accepting connections from anything but the local host and port-forwarded connections sent using SSH as a result of the -via option.
SSH, see Chapter 12, OpenSSH.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.