Home » Home Server » How to setup VNC server on Ubuntu for remote desktop access

How to setup VNC server on Ubuntu for remote desktop access

In the Linux world, VNC is a commonly heard term. The VNC abbreviation stands for Virtual Network Computing. It is a graphical desktop sharing system made to remotely control another computer. VNC is platform-independent, having clients and servers for many operating systems using a graphical user interface (GUI). Learn how to setup VNC server on Ubuntu and how to configure VNC server on Ubuntu.

Prerequisites for Ubuntu VNC setup

Before we start to setup VNC server on Ubuntu, we need to prepare the server by updating the system packages and installing a desktop environment on the server.

Update the system packages:

sudo apt-get update && sudo apt-get upgrade -y

Next, install the Ubuntu Gnome desktop environment:

sudo apt-get install --no-install-recommends ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal -y

Note that if you are running a GUI version of Ubuntu, the desktop environment part is not needed in order to install and configure VNC server on Ubuntu.

Setup VNC server on Ubuntu

Now that we updated the system packages and we have a desktop environment, we can continue with the Ubuntu VNC setup by installing the VNC server package.

Install the VNC server:

sudo apt-get install vnc4server -y

Setup VNC server to run on 5901 port or 1 subport:

sudo nano /etc/systemd/system/[email protected]:1.service

Paste the following configuration and replace my user (ciprian) with your server user:

<pre>[Unit]
Description=Start VNC4server server at startup
After=syslog.target network.target

[Service]
Type=forking
User=ciprian
PAMName=login
PIDFile=/home/ciprian/.vnc/%H%i.pid
#ExecStartPre=/usr/bin/vncserver -kill %i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1024x768 %i
ExecStop=/usr/bin/vncserver -kill %i

[Install]
WantedBy=multi-user.target</pre>

Restart the systemctl daemon using sudo

sudo systemctl daemon-reload

Recommended Reading:

Configure VNC server on Ubuntu

In order to configure VNC server on Ubuntu, we first need to start the VNC server.

Start the VNC server with your current user:

vncserver

Create a password for the VNC connection. This is the password used to login to your VNC server.

Create a password for the VNC connection - setup vnc server on ubuntu
Create a password for the VNC connection

Stop the VNC server:

vncserver -kill :1

Next, we need to configure the desktop environment to load all the required extensions in your Ubuntu VNC setup. Open the xstartup file:

sudo nano /home/ciprian/.vnc/xstartup

Add the following commands to the xstartup file for the desktop environment to load correctly, like in the screenshot below:

gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
Edit the xstartup file as shown - setup vnc server on ubuntu
Edit the xstartup file as shown

When you configure VNC server on Ubuntu, make sure you configure the VNC server to start automatically. Open crontab and select the second option:

crontab -e
When opening crontab for the first time, select the second option - setup vnc server on ubuntu
When opening crontab for the first time, select the second option

Edit the crontab file as shown:

Add the @reboot /usr/bin/vncserver :1 line to the config file, then press CTRL+X to save the file.

Edit crontab as shown - ubuntu vnc setup
Edit crontab as shown

You can now reboot your computer and connect to the VNC Server. Open VNC viewer and enter the server with the subport.

Enter the hostname for the VNC server and the subport
Enter the hostname for the VNC server and the subport

Type the login password.

Enter the login password for the VNC Server
Enter the login password for the VNC Server

You are now connected!

You are now connected to the server using VNC - configure vnc server on ubuntu
You are now connected to the server using VNC

The VNC server is now running: What you can do next

Congratulations. Now you can remotely connect to your Ubuntu machine anytime you need to. Next, you can learn how to install Docker on Ubuntu to run apps in containers. If you don;t know about Docker, make sure you check the What is Docker: Docker vs VirtualBox article and learn more about it. Check back soon for more VNC articles.

We Are Hiring: Familiar with Media Streaming, HTPC, Home Server, Smart Home, and Home Automation topics? Write about it and earn money. No writing experience needed. APPLY HERE.

Get 20% OFF with IPVanish VPN:

♦   Hide your browsing and streaming activity: No logs and no tracking
♦   Access geo-restricted content from anywhere
♦   Encrypt and anonymize: Kodi, Plex, Downloads, Personal Info
♦   Windows, Mac, Linux, Android, iOS, Router, and more.
♦   Money back guarantee - Sign Up Now

About the author

Ciprian

Ciprian is an enthusiast, always up to date with the latest and greatest in the IT field. Passionate about computers, mobile devices and gadgets. In his spare time, he is a gamer.

Smart Home Beginner

Join the other 110,000 followers