Install and Configure VNC Server in RHEL7

Make sure the desktop is installed
# yum groupinstall "GNOME Desktop"

Install TigerVNC and other dependency
# yum install tigervnc-server xorg-x11-fonts-Type1

Setup the VNC server config file
Copy the file “/lib/systemd/system/vncserver@.service” to “vncserver@:<Port_Number>.service”.
While Copying the VNC config file we can mention the port number on which we want VNC service to be listen. In my case I am using port 7 and 8, it means VNC will listen on “5907” and “5908”. So while Connecting to the VNC server We can specify port number as <IP_Address_VNC_Server:7> and <IP_Address_VNC_Server:8> or <IP_Address_VNC_Server:5907> and <IP_Address_VNC_Server:5908>.
# cd /lib/systemd/system
# cp vncserver@.service vncserver@:7.service
# cp vncserver@.service vncserver@:8.service

Update user’s information in the config file
For instance of port number :7
# vim vncserver@:7.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver_wrapper jim %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

Set the firewall rule if firewall is enabled on your Linux
# firewall-cmd --permanent --zone=public --add-port=5901-5999/tcp
# firewall-cmd --reload

Start and enable VNC service at boot
# systemctl daemon-reload
# systemctl start vncserver@:7.service
# systemctl start vncserver@:8.service
# systemctl enable vncserver@:7.service
# systemctl enable vncserver@:8.service