What is VNC?
VNC or Virtual Network Computing is an independent platform that allows you to remote and control another computer desktop with GUI (Graphical User Interface) over the network connection.
It’s desktop-sharing software that transmits keyboard and mouse events from one computer to another through the RFB (Remote Frame Buffer) protocol.
The VNC works on the client-server model architecture. A VNC Client uses the VNC viewer application (installed on the client-side) to connect and remote to the VNC server, which is the VNC Server components installed on it.
In this tutorial, you will learn how to install VNC Server on Ubuntu 18.04 Server. You will install Graphical Desktop Environment XFCE, setup the VNC Server, and connect securely to the VNC server through SSH Tunnel.
For this tutorial, make sure you have got a Ubuntu 18.04 server with root privileges. Also, you need to install a VNC Viewer on your local computer.
Below is the tutorial about the Ubuntu 18.04 server installation.
Before going any further, log in to your Ubuntu server and type the sudo command to get the root privileges on your system.
Step 1 – Install XFCE Desktop Environment on Ubuntu 18.04
First, you will install the Desktop Environment (DE) on the Ubuntu 18.04 Server. You will use the mid-range DE with low-memory consumption XFCE Desktop as default DE for the VNC Server on Ubuntu system.
Update the Ubuntu repository list and install XFCE Desktop using the apt command below.
apt update apt install xfce4 xfce4-goodies
Wait for the XFCE packages installation.
Once all installation completed, move to the next stage.
Step 2 – Install and Configure VNC Server
After installing the XFCE to the Ubuntu system, you will install the VNC Server components.
You will install the ‘tightvncserver’ packages, initialize the VNC Server configuration for the specific user, and setup XFCE Desktop as default DE for VNC Server.
Install ‘tightvncserver’ packages to the Ubuntu system using the apt command below.
apt install tightvncserver
As a result, you’ve installed ‘tightvncserver’ to the Ubuntu 18.04 Server.
– Initial Configuration
In this stage, you will initialize the VNC Server configuration for the specific. For this guide, we’re using the user named ‘chaewon’ with sudo root privileges.
Login to your user using the following command
su - chaewon
Initialize the VNC Server configuration using the ‘vncserver’ command as below.
Now type your VNC Server password (6-8 characters) and verify it.
You will require a password to access your desktops. Password: Verify:
Next, you will be asked for the ‘view-only’ password configuration. The ‘view-only’ password will allow you to limit the user from using their mouse and keyboard to control the VNC Server desktop. This is useful for demonstrating to other users, but not required.
Would you like to enter a view-only password (y/n)? n
Once the initialization is complete, you will be displayed the following output.
xauth: file /home/chaewon/.Xauthority does not exist New 'X' desktop is vnc-server:1 Creating default startup script /home/chaewon/.vnc/xstartup Starting applications specified in /home/chaewon/.vnc/xstartup Log file is /home/chaewon/.vnc/vnc-server:1.log
As a result, you’ve successfully initialized the VNC Server configuration, and you’ve set up the VNC Server password. All configuration for VNC Server located at ‘~/.vnc’ directory.
Also, the first VNC Server is running on the display-port ‘vnc-server:1’. You can launch multiple VNC Server process on other ports such as ‘:2’, ‘:3’, etc.
– Setup XFCE as Default DE for VNC Server
After initializing the VNC Server configuration, you will setup the XFCE Desktop as a default Desktop Environment for the VNC Server session.
Before going any further, kill the first VNC Server display-port using the following command.
vncserver -kill :1
Now you will be displayed the result as below.
Killing Xtightvnc process ID 2166
Next, backup the default VNC configuration “~/.vnc/xstartup” and create another one.
mv ~/.vnc/xstartup ~/.vnc/xstartup.orig vim ~/.vnc/xstartup
Paste the following configuration to set up the XFCE as default Desktop Environment for the VNC Server.
#!/bin/bash xrdb $HOME/.Xresources startxfce4 &
Save and close.
Next, make the VNC Server startup script executable using the chmod command below.
chmod +x ~/.vnc/xstartup
As a result, you’ve successfully set up the XFCE as default DE for your VNC Server.
Additionally, you can create the “~/. Xresources” configuration to set up the default DPI, anti-aliasing, hinting, terminal colors, terminal preferences, etc.
Create a new “~/.Xresources” configuration using vim editor.
Paste the following configuration into it.
############## # Xft settings ############## Xft.dpi: 96 Xft.antialias: true Xft.rgba: rgb Xft.hinting: true Xft.hintstyle: hintslight
Save and close.
As a result, you’ve created the “~/. Xresources” file to configure the default DPI, anti-aliasing, and hinting.
– Start VNC Server with XFCE Desktop
Now test the new VNC Server configuration using the ‘vncserver’ command below.
Make sure there is no error, and you will be displayed the result as below.
The VNC Server is up and running with the XFCE as the default DE.
Step 3 – Set up VNC Server as a Service
In this step, you will configure the VNC Server to run as a systemd service.
First, kill the VNC Server process that we’re running on top.
vncserver -kill :1
Now go to the ‘/etc/systemd/system’ directory and create a new service file ‘[email protected]’ using vim editor.
cd /etc/systemd/system/ vim [email protected]
Change the default user with your own and paste the configuration into it.
[Unit] Description=Start TightVNC server at startup After=syslog.target network.target [Service] Type=forking User=chaewon Group=chaewon WorkingDirectory=/home/chaewon PIDFile=/home/chaewon/.vnc/%H:%i.pid ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x960 :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target
Save and close.
Next, reload the systemd manager.
Start the VNC Server service and add it to the system boot, then check it’s service status.
systemctl enable --now [email protected] systemctl status [email protected]
As a result, the VNC Server is up and running as a systemd service. Below is the result displayed to you.
Also, you’re ready to connect to the VNC Server.
Step 4 – Install VNC Server on Client
To connect to the VNC Server, you must install the VNC Viewer software on your local computer. You can use UltraVNC, RealVNC, or TigerVNC Viewer.
For Windows users, download and install RealVNC Viewer from the following URL.
And cor Mac users, download and install RealVNC Viewer from the following URL.
For Ubuntu users, you can install the ‘TigerVNC Viewer’ from the Ubuntu repository using the apt command below.
apt install tigervnc-viewer
Optionally, you use RealVNC for Debian based operating system.
Download the RealVNC Package for Linux Debian from the URL below.
Now install the RealVNC Viewer using the “dpkg” command below.
sudo dpkg -i VNC-Viewer-*.deb
As a result, you’ve successfully installed the VNC Viewer software to your local computer.
Step 5 – Connect to VNC Server with SSH Tunneling
It’s important to connect to your VNC Server securely. To do that, you can use the special VPN connection installed on the server, or using the simple SSH tunneling.
For this step, you will learn how to connect to the VNC Server securely through the SSH Tunneling.
First, create a new SSH tunneling connection to the VNC Server port ‘5901‘ using the SSH command below.
ssh -L 5901:127.0.0.1:5901 -C -N -l chaewon 10.5.5.25
Change the ‘chaewon’ user with your own and type your password.
Next, open your VNC Viewer software (we’re using RealVNC Viewer) and type the localhost address ‘127.0.0.1‘ with default VNC Server port ‘5901‘ and press Enter to connect.
Now type your VNC Server password and click “OK” to continue.
Now you will be prompted about the unsecure connection to ‘localhost’, it’s fine because you’re connected locally, click the ‘Continue‘ button and you will get the default XFCE Desktop.
As a result, you’ve successfully connected to the VNC Server securely through the SSH Tunneling.
Finally, you’ve installed the VNC Server on Ubuntu 18.04 Server with the XFCE as a default Desktop Environment. Also, you’ve successfully connected securely to the VNC Server through SSH Tunneling.