In this article, we will have explained the necessary steps to install and configure VNC on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with
sudo privileges. All the commands in this tutorial should be run as a non-root user.
Virtual Network Computing (VNC) is a graphical desktop sharing system that allows you to use your keyboard and mouse to remotely control another computer.
Install VNC on Ubuntu 20.04
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install the Graphical Desktop Packages.
Let’s install the XFCE desktop environment:
sudo apt install xfce4 xfce4-goodies
During this installation, you may be prompted to pick a display manager for the system’s graphical desktop. Use the arrow keys to select lightdm on this screen and hit enter to continue.
Once done, install the TightVNC server package:
sudo apt install tightvncserver
Step 3. Create a VNC user.
Now create the new user and set its server password with the following commands:
sudo useradd -m -s /bin/bash linuxtipsuser sudo passwd linuxtipsuser
Next, add your new user to the
sudo group to grant root privileges:
sudo usermod -a -G sudo linuxtipsuser sudo su - linuxtipsuser
Step 4. Configure VNC Server.
Now that the VNC server is installed the next step is to run the
vncserver the command which will create the initial configuration and set up the password. Do not use
sudo when running the following command:
The screen output walks you through setting a VNC-specific password (limited to 8 characters), then you’re prompted on whether you wish to create a view-only password:
You will require a password to access your desktops. Password: Warning: password truncated to the length of 8. Verify: Would you like to enter a view-only password (y/n)? y Password: Warning: password truncated to the length of 8. Verify: xauth: file /home/linuxtipsuser/.Xauthority does not exist xauth: (argv):1: bad display name "linuxtips-86:1" in "add" command xauth: file /home/linuxtipsuser/.Xauthority does not exist New 'X' desktop is linuxtips-86:1 127.0.0.1 localhost Creating default startup script /home/linuxtipsuser/.vnc/xstartup Starting applications specified in /home/linuxtipsuser/.vnc/xstartup Log file is /home/myvncuser/.vnc/linuxtips-86:1.log
Now that we’ve started the VNC server for the first time, some basic configuration files were created. We also want to set some commands to be run automatically every time
vncserver starts up:
vncserver -kill :1
Next, create a backup of its default startup script file:
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
Now use nano text editor to create a new
Paste the following 3 lines of text into your new file:
#!/bin/bash xrdb $HOME/.Xresources startxfce4 &
Once done, run other commands from its startup, grant executable privileges to your new startup file with the following command:
sudo chmod +x ~/.vnc/xstartup
Step 6. Testing Your Connection.
Set up a secure SSH tunnel by running the following command on your local machine (you can open up a new window or tab in Terminal, for example). Replace your-server-ip with the IP address of your server:
ssh -L 5901:127.0.0.1:5901 -N -f -l linuxtipsusser server_ip
Connecting to CentOS Desktop via VNC Client.
In this example, we’ll be using TigerVNC. Open your VNC viewer, enter localhost:5901, and click on the Connect button.
That’s all you need to do to install the VNC server on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. For further reading on VNC, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.