How to Install VNC on Ubuntu 18.04

r00t July 23, 2018

Install VNC on Ubuntu 18.04

In this tutorial we are going to learn how to install VNC on Ubuntu 18.04. We will also install and configure its prerequisites. VNC (Virtual network computing) is a graphical desktop sharing system which will allow you to connect to a computer, view its graphical interface and control it remotely using a VNC client. It makes managing files, software, and settings on a remote server easier for users who are not yet comfortable with the command line.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 18.04 LTS Bionic Beaver minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install VNC on Ubuntu 18.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Installing VNC on Ubuntu 18.04 Bionic Beaver.

First, install Graphical Desktop Environment and required packages of from official Ubuntu Repository:

sudo apt install xfce4 xfce4-goodies

Install the VNC server using the following command:

sudo apt install vnc4server

Once the VNC server is installed we can begin the configuration by setting up a user password to be used by a VNC client when creating a remote connection:

vncpasswd

To finalize the installation just type vncserver in the command line to enter:

vncserver

The setup will ask you to setup a password. Enter the password and confirm it. Then you will be asked to enter the view only password.

Step 3. Configuring Ubuntu VNC server.

We are now going to make some changes in the xstartup file:

mkdir ~/.vnc
nano ~/.vnc/xstartup
~/.vnc/xstartup

Insert the the following content and save:

#!/bin/bash
startxfce4 &

For VNC to execute this new startup file, we have to grant the privileges to execute the file:

sudo chmod +x ~/.vnc/xstartup

Next, restart the server:

vncserver

Now, you will get the following output:

New 'X' desktop is your_name_server.com:1

Step 4. Create VNC server system startup script.

Next, setup a systemd startup script in order to easily manage multiple VNC desktop sessions:

nano /etc/systemd/system/vncserver@.service

Add following content:

[Unit]
Description=Systemd VNC server startup script for Ubuntu 18.04
After=syslog.target network.target

[Service]
Type=forking
User=ramona
ExecStartPre=-/usr/bin/vncserver -kill :%i &> /dev/null
ExecStart=/usr/bin/vncserver -depth 24 -geometry 800x600 :%i
PIDFile=/home/myvpsource/.vnc/%H:%i.pid
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Next, reload the Systemd:

sudo systemctl daemon-reload
sudo service vncserver@1 start
sudo systemctl enable vncserver@1

Step 5. Testing the VNC.

You have to check your VNC. You have to connect to the remote server using SSH connection and forward the connection to the localhost connection:

ssh -L 5901:127.0.0.1:5901 -N -f -l username server_ip_address

If you are using Windows, install TightVNC and Putty.

Congratulation’s! You have successfully install and configured VNC on your Ubuntu 18.04 server. Thanks for using this tutorial installing VNC remote dekstop on Ubuntu 18.04 LTS (Bionic Beaver) system.

The Tags:

Leave a Comment

Comments are closed.