Install and configure VNC Server on Linux

Description

In this article I will describe the step by step Installation and Configuration of VNC Server on Linux 7 environments.

We will be covering the following steps:

  1. VNC Server Prerequisites and rpm installation
  2. Configure VNC Server
  3. Start the VNC Service
  4. Enable VNC Server
  5. Accessing the GUI using VNC Server
1. VNC Server Prerequisites and rpm installation

Note: Before installing the VNC server, Make sure the OS is installed with GNOME Desktop.

For configuring VNC Server, the following packages has to be installed.

# yum install tigervnc-server
# yum install xorg-x11-fonts-Type1
2. Configure VNC Server

Copy the VNC configuration file /lib/systemd/system/vncserver@.service to /etc/systemd/system directory and mention the port which has to connect. By default VNC will listen to port 5900.

# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service

Here I have mentioned port 2, so that the VNC Desktop will be accessible on port 5902.

Manually edit the copied file /etc/systemd/system/vncserver@:2.service and replace <USER> to your username
In the below example I have replaced <USER> with oracle

# vi /etc/systemd/system/vncserver@:2.service
[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 oracle %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

Or you may use sed command to replace the string,

# sed -i 's/<USER>/oracle/g' /etc/systemd/system/vncserver@:2.service
3. Start the VNC Service

Switch to Oracle user and start the VNC Service

# vncserver

Output:

[oracle@ol7-dev ~]$ vncserver
Warning: ol7-dev:1 is taken because of /tmp/.X11-unix/X1
Remove this file if there is no X server ol7-dev:1
xauth: file /home/oracle/.Xauthority does not exist
New 'ol7-dev:2 (oracle)' desktop is ol7-dev:2
Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/ol7-dev:2.log
[oracle@ol7-dev ~]$
4. Enable the VNC Service

Switch to root user and enable the vncserver service for oracle user on port 5902. This will also enable autostart on system boot.

Switch to root user:

# su -

Reload systemd’s configuration

# systemctl daemon-reload

Configure the VNC password for user oracle

# vncpasswd oracle

Start and enable the VNC Server service. This will enable the auto start on system boot

# systemctl start vncserver@:2.service
# systemctl enable vncserver@:2.service
5. Accessing the GUI using VNC Server

Download and install any VNC viewer on your client PC to access the VNC Server. Here I am using VNC Viewer (Here is the download link)

Enter the VNC Server IP and

Enter the VNC password

You are now connected to the VNC Server.

Hope this helps…