---
title: "How To Provision an Ubuntu VNC Server"
description: "Learn to facilitate remote access and deploy an Ubuntu VNC Server in this step-by-step tutorial!"
canonical: "https://adamtheautomator.com/ubuntu-vnc-server/"
---

# How To Provision an Ubuntu VNC Server

> Learn to facilitate remote access and deploy an Ubuntu VNC Server in this step-by-step tutorial!

Source: https://adamtheautomator.com/ubuntu-vnc-server/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How To Provision an Ubuntu VNC Server](https://adamtheautomator.com/wp-content/uploads/2022/03/How-To-Provision-an-Ubuntu-VNC-Server.jpg)

# How To Provision an Ubuntu VNC Server

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)17 March 20227 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Command Line](/tag/command-line/)[Ubuntu Linux](/tag/ubuntu-linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing the Ubuntu VNC Server](#installing-the-ubuntu-vnc-server)
*   [Configuring the Ubuntu VNC Server Desktop Manager](#configuring-the-ubuntu-vnc-server-desktop-manager)
*   [Securing Ubuntu VNC Server Access](#securing-ubuntu-vnc-server-access)
*   [Setting Up Ubuntu VNC Server as a Service](#setting-up-ubuntu-vnc-server-as-a-service)
*   [Conclusion](#conclusion)

Do you manage Ubuntu servers but aren’t fans of doing everything in the command line? Maybe you’re more comfortable managing servers via remote desktop (and that’s perfectly alright). Lucky for you, there’s a way to access your systems remotely by setting up an Ubuntu [VNC](https://discover.realvnc.com/what-is-vnc-remote-access-technology) server.

## **Prerequisites**

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have the following.

*   You need an Ubuntu server. This tutorial uses Ubuntu Server 20.04.

Related:[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)

*   You have [installed a Desktop Environment](https://linuxconfig.org/ubuntu-20-04-gui-installation) on the server. This tutorial will be using the [**XFCE**](https://xfce.org/) desktop on Ubuntu.
    
*   You’ll need an SSH client for logging in to the server remotely.
    

Related:[Getting Started using SSH with PowerShell](https://adamtheautomator.com/powershell-ssh/)

*   You must have a non-root user account with **[sudo privileges](https://www.liquidweb.com/kb/how-to-set-up-and-manage-sudo-permissions/).**
*   You also need a VNC client such as the [VNC Viewer](https://www.realvnc.com/en/connect/download/viewer/), which this tutorial will use.

## Installing the Ubuntu VNC Server

By default, Ubuntu does not have a VNC server installed. You will need to install the Ubuntu VNC server first before you can access your server’s remote desktop.

**[TightVNC](https://www.tightvnc.com/)** is a popular VNC server known for its low resource requirements and fast performance. As such, _TightVNC_ is a good Ubuntu VNC server choice for smooth and stable VNC sessions, even on slow internet connections.

Follow the below steps to install _TightVNC_.

1\. First, open your SSH client and log in to the Ubuntu server.

2\. Run the command below to ensure that your Ubuntu server has the latest package lists.

```bash
sudo apt update -y
```

Related:[Learning Ubuntu Apt Get Through Examples](https://adamtheautomator.com/ubuntu-apt-get/)

3\. Now, install the TightVNC server by running the below command. `sudo apt install tightvncserver -y`

```bash
sudo apt install tightvncserver -y
```

Wait for the installation to complete, and you should get a result similar to the screenshot below.

![Installing TightVNC as an Ubuntu VNC server](https://adamtheautomator.com/wp-content/uploads/2022/03/image-221.png)

Installing TightVNC as an Ubuntu VNC server

4\. After installing, the VNC server does not start automatically. To manually start the VNC server, run the below command.

```bash
vncserver
```

5\. The first time you start a VNC instance, the server will ask you to create a password. Type in the new secured password and press **Enter**. You will need this password to remotely connect to your VNC server from another machine.

> _The password must be within six and eight characters long. Passwords longer than eight characters will be truncated to fit the maximum of eight characters long._

After creating a password, `vncserver` asks you to set a _View-only_ password. This option allows users to view your VNC session without the ability to control it. Do not set a _View-only_ password at this time. Input `n` and press Enter.

![Creating a new VNC server password ](https://adamtheautomator.com/wp-content/uploads/2022/03/image-222.png)

Creating a new VNC server password

> _If you need to change the VNC password later, you can do so by running the `vncpasswd` command._

6\. Once you press **Enter**, `vncserver` will start and you will see the following output. `vncserver` creates a startup script named `.vnc/xstartup` under your home directory.

![Starting the Ubuntu VNC server instance](https://adamtheautomator.com/wp-content/uploads/2022/03/image-223.png)

Starting the Ubuntu VNC server instance

> **_5_**_**901 is** the default VNC port, also called the display port. The last digit represents the VNC server instance number. If you need to start another VNC server instance, run the `vncserver` command and append the instance number._
> 
> _For example, to start a VNC server instance on port **5902** (instance 2), run the command `vncserver :2`._

## Configuring the Ubuntu VNC Server Desktop Manager

At this point, you have a running Ubuntu VNC server. But before you can start using it, you need to tell your VNC server the default desktop environment to launch when you log in.

1\. Before making any changes, kill the default VNC server instance running on port 5901 by running the following command. `vncserver -kill :1` ![Stopping the Ubuntu VNC server instance](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/1219b9c5-2ab0-4420-b5e0-a0a342cb4b26/Untitled.png) Stopping the Ubuntu VNC server instance

```bash
vncserver -kill :1
```

> _In case you have more than one VNC server instance running, you can kill them with `vncserver -kill :2` and `vncserver -kill :3`, and so on._

2\. Make a backup of the default VNC server configuration file by running the following command. You should back up the file if you need to revert the changes.

```bash
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
```

3\. Now, open the `~/.vnc/xstartup` file for editing. This example uses `nano` as the text editor.

Related:[How to Edit Files with a Real PowerShell Text Editor](https://adamtheautomator.com/powershell-text-editor/)

```bash
nano ~/.vnc/xstartup
```

4\. Populate the file with the following code. To better understand the code, below are a brief explanation of each line.

*   `#! /bin/bash`: This line tells the system what interpreter to use to execute the succeeding commands. In this case, the Bash interpreter.
*   `xrdb $HOME/.Xresources`: This line tells the VNC server to read the user’s _`.Xresources`_ file (if exists). This file contains settings that modify the look and feel of the graphical desktop, like graphical colors and font rendering.
*   `startxfce4 &`: This line starts the XFCE desktop environment. You can substitute this line with `startkde` or `startgnome` if you are using **[KDE](https://kde.org/)** or **[GNOME](https://www.gnome.org/)** desktop environments, respectively. The `&` symbol at the end tells the command to run in the background

```bash
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
```

Your file should look similar to the screenshot below. ![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/86de6cf4-ad83-4ef1-9aea-c7dfa4a97c4a/Untitled.png)

![The & symbol at the end tells the command to run in the background](https://adamtheautomator.com/wp-content/uploads/2022/03/image-224.png)

The `&` symbol at the end tells the command to run in the background

5\. Next, make the _`xstartup`_ file executable. The below command tells the system to give the file owner (you) execute permission for the file.

```bash
chmod +x ~/.vnc/xstartup
```

## Securing Ubuntu VNC Server Access

By default, the VNC server accepts incoming connections from any host. This default setting leaves your Ubuntu VNC server open to anyone who knows your IP address – which can be a security risk.

You can secure your VNC connection by using an SSH tunnel. The SSH tunnel will create a secure connection between your local computer and the Ubuntu VNC server. This way, you would not need to open new ports on your firewall to allow connectivity to your VNC server instances.

1\. First, start a VNC server instance on your server by running the command below. The `-localhost` parameter binds the VNC server instance to the server’s loopback interface. This VNC instance will only accept connections locally and effectively lock down access from anywhere else.

```bash
vncserver -localhost
```

2\. Once you’re started a VNC server instance, open a new terminal window on your computer and establish an SSH tunnel to the remote Ubuntu VNC server by running the below `ssh` command line. To better understand the command, refer to the inline comments.

```bash
# Create an SSH Tunnel to the Ubuntu VNC Server
## -L : creates a secure tunnel from the local port (59000) to the remote port (5901) on the VNC server.
## -C : compress all data sent through the tunnel to optimize bandwidth usage.
## -N : tells ssh not to execute any remote commands, and you will not get a shell.
## -l : to specify the username to log in. Do not use a root account here.
## SSHServer : replace this with your Ubuntu VNC server’s IP address, FQDN, or hostname.
ssh -L 59000:localhost:5901 -C -N -l username SSHServer
```

If you’re connecting to the server for the first time, `ssh` will ask you to confirm the host’s fingerprint. Type `yes` and press Enter.

Type in the user account password at the password prompt and press Enter. At this point, the SSH tunnel is now open. Do not close the terminal, or the SSH tunnel will terminate, too.

![Creating the SSH tunnel](https://adamtheautomator.com/wp-content/uploads/2022/03/image-225.png)

Creating the SSH tunnel

3\. Now, open your preferred [VNC viewer](https://www.realvnc.com/en/connect/download/viewer/) on your computer. Type `localhost:59000` in the address text box at the top and press **Enter**.

![Connecting to the VNC server](https://adamtheautomator.com/wp-content/uploads/2022/03/image-226.png)

Connecting to the VNC server

4\. Type in your VNC password into the authentication prompt and click **OK**.

![Connecting to the VNC session ](https://adamtheautomator.com/wp-content/uploads/2022/03/image-227.png)

Connecting to the VNC session

You will now have a secure connection to your VNC desktop, as shown below.

![Accessing the remote desktop via VNC](https://adamtheautomator.com/wp-content/uploads/2022/03/image-228.png)

Accessing the remote desktop via VNC

## Setting Up Ubuntu VNC Server as a Service

The VNC server installs without a built-in daemon. This situation means that by default, you’ll need to start the VNC server instance manually every time you need to access the remote desktop.

But you can work around that limitation by turning the VNC server into a service – which runs automatically at startup. And below are the steps to enable the Ubuntu VNC server to autostart.

1\. First, kill the running VNC server instance.

```bash
vncserver -kill :1
```

2\. Run the below command to create a new [**systemd unit file**](https://manpages.ubuntu.com/manpages/bionic/man5/systemd.unit.5.html) and open it in `nano` for editing. The unit name can be anything you want. In this example, the name would be `atavncserver.service`.

```bash
sudo nano /etc/systemd/system/atavncserver.service
```

Next, copy the code below and paste it into your text editor.

Make sure to replace every instance of the word `USERNAME` with your username.

To adjust the color depth and screen resolution, modify the `-depth` and `-geometry` parameter values, respectively. In this example, the color depth is `24` (bit), and the resolution is `1280x800`.

```bash
[Unit]
Description=VNC Server
After=syslog.target network.target
[Service]
Type=forking
User=USERNAME
Group=USERNAME
WorkingDirectory=/home/USERNAME
PIDFile=/home/USERNAME/.vnc/%H:1.pid
ExecStartPre=-/usr/bin/vncserver -kill :1 > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 -localhost :1
ExecStop=/usr/bin/vncserver -kill :1
[Install]
WantedBy=multi-user.target
```

Save the file by pressing `Ctrl+O` → `Enter` → `Ctrl+X`.

4\. Next, run the below reload the `systemd` service manager configuration. This step essentially adds the service you created to the available service list. `sudo systemctl daemon-reload`

```bash
sudo systemctl daemon-reload
```

5\. Now that the system recognizes the new `atavncserver` service run the below command to enable that service.

```bash
sudo systemctl enable atavncserver.service
```

6\. Start the VNC server instance as a service by running this command.

```bash
sudo systemctl start atavncserver
```

7\. To find out if the service has started, run the below command to check the service status. `sudo systemctl status atavncserver`

```bash
sudo systemctl status atavncserver
```

You should see a similar to the screenshot below showing that the service status is `active (running)`.

![Checking the VNC server daemon status](https://adamtheautomator.com/wp-content/uploads/2022/03/image-229.png)

Checking the VNC server daemon status

You now have a Ubuntu VNC server service that runs at startup automatically. And being a service, you can now perform the `start`, `stop`, `reload`, and `restart` with the `systemctl` command.

Related:[Controlling Systemd services with Ubuntu systemctl](https://adamtheautomator.com/ubuntu-systemctl/)

## Conclusion

In this tutorial, you have learned how to install and configure an Ubuntu VNC server. You have also learned to secure your VNC connection with an SSH tunnel. At this point, you should be able to connect to your VNC desktop from any computer or device securely and easily.

Perhaps you could try [setting up VNC Connect on Raspberry Pi](https://www.thesecmaster.com/step-by-step-tutorial-to-set-up-vnc-on-raspberry-pi/) devices next with this newfound knowledge? Thank you for reading, and happy learning!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-vnc-server%2F&text=How%20To%20Provision%20an%20Ubuntu%20VNC%20Server)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-vnc-server%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-vnc-server%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Comprehensive-Guide-to-Installing-Deb-Packages-on-Ubuntu.jpg)

### [Comprehensive Guide to Install Deb Packages on Ubuntu](/install-deb-packages-on-ubuntu/)

Learn all the ways to install deb packages on Ubuntu, fix problems, and save your sanity with this comprehensive guide!

![](https://adamtheautomator.com/wp-content/uploads/2022/08/How-to-Install-Metasploit-on-Ubuntu.jpg)

### [How to Install Metasploit on Ubuntu](/install-metasploit-on-ubuntu/)

Learning to install Metasploit on Ubuntu isn’t just for malicious actors, learn why in this tutorial on getting started with Metasploit!

![](https://adamtheautomator.com/wp-content/uploads/2022/08/Install-Oh-My-Zsh-on-Ubuntu-For-a-Next-Level-Command-Line-1.jpg)

### [Install Oh My Zsh on Ubuntu For a Next Level Command-Line](/install-oh-my-zsh-on-ubuntu/)

Learn how to install Oh My Zsh on Ubuntu and take your command-line to the next level in this ATA Learning tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
