Skip to content

How to Install VNC Server on Ubuntu | Easy Setup Guide

When you’re running an Ubuntu server, most of your time is probably spent in a command-line terminal over SSH. It’s fast and efficient, but what happens when you need to run an application with a graphical user interface (GUI)? That’s where Virtual Network Computing (VNC) comes in.

VNC essentially streams the entire graphical desktop from your Ubuntu server to your local machine. You get a complete visual experience, allowing you to click, drag, and type just as if you were physically there.

This is incredibly practical for a few common situations:

  • Easier Server Management: Sometimes it’s just faster to manage files, system settings, or user accounts with a familiar graphical interface instead of hunting down the right command.
  • Running GUI-Based Tools: If you need to use development tools, database clients, or data visualization software on your server, VNC makes it possible.
  • Remote Technical Support: VNC is perfect for helping a user by viewing and interacting with their desktop to troubleshoot a problem live.

Choosing the Right VNC Server and Desktop Environment

To get VNC running, you need two things: a VNC server to run on your Ubuntu machine and a desktop environment for it to display. For a server, you want to keep things as lightweight as possible to save precious CPU and RAM.

This is why the combination of TightVNC Server and the Xfce desktop environment is such a go-to choice.

TightVNC is celebrated for its efficiency and smart use of bandwidth, making it responsive even over slower connections. Xfce delivers a clean, functional desktop that has all the essentials without the performance overhead of heavier environments like GNOME or KDE.

This need for a manual VNC setup has become more common, especially since newer versions like Ubuntu 22.04 LTS Server don’t ship with a GUI out of the box. Setting one up yourself gives you complete control.

To help you decide, here’s a quick look at some popular options.

VNC Server and Desktop Environment Choices

ComponentOption 1 (Recommended)Option 2 (Alternative)Key Benefit
VNC ServerTightVNC ServerTigerVNCPerformance: TightVNC is optimized for low bandwidth usage.
Desktop EnvironmentXfceLXDE/LXQtLightweight: Xfce provides a great balance of features and low resource use.

Ultimately, our guide will focus on the recommended TightVNC and Xfce pairing because it’s a reliable and resource-friendly combination perfect for most server use cases.

While VNC is a fantastic, platform-agnostic solution, it’s also good to be aware of other protocols out there, like Microsoft’s Remote Desktop Protocol (RDP). Each has its own strengths, but for Linux servers, VNC is a flexible and powerful standard.

Getting Your Ubuntu System VNC-Ready

Image

Before we even think about installing the VNC server, the first order of business is to make sure our Ubuntu system is fully up to date. Starting with a fresh, updated system prevents potential dependency conflicts and security gaps down the line.

Step 1: Update Your System’s Package List

This command refreshes your local package index, syncing it with Ubuntu’s repositories to identify the latest available software versions.

sudo apt update

Step 2: Install the Latest Updates

Now, apply all available upgrades to your installed packages. The -y flag automatically confirms any prompts, streamlining the process.

sudo apt upgrade -y

Think of this as laying a solid foundation. A clean, updated system is crucial for a stable VNC setup. Skipping this step is just asking for trouble when you install the desktop environment and VNC server.

Installing a Lightweight Desktop Environment

VNC needs a graphical interface to display. On a server, it’s best to choose a desktop environment that is light on resources to avoid slowing down your system. Our recommended choice is Xfce, a fast and efficient option that provides a full desktop experience without unnecessary bloat.

Step 3: Install the Xfce Desktop Environment

We can install Xfce and a collection of useful add-ons with a single command. The xfce4-goodies package includes essential tools like a file manager and terminal emulator, which are vital for a complete remote desktop session.

Run this command to install the necessary packages:

sudo apt install xfce4 xfce4-goodies -y

This installation may take a few minutes as it downloads and configures all the components for your new graphical interface. Once finished, your server will have the desktop environment needed for VNC.

Getting Your VNC Server Up and Running

Now that you’ve got the Xfce desktop environment ready to go, it’s time to install the VNC server itself. We’re going with TightVNC Server, a solid and lightweight choice that’s conveniently available right from Ubuntu’s default software repositories.

Step 1: Install TightVNC Server

Use the following command to download and install the VNC server package.

sudo apt install tightvncserver -y

Step 2: Run VNC Server for Initial Setup

After installation, you need to run the vncserver command for the first time. This critical step accomplishes two things: it creates the necessary configuration files and prompts you to set a password for accessing your VNC desktop.

vncserver

You will be asked to create a password. Choose a strong, secure password. You’ll also be asked if you’d like to create a view-only password; you can safely decline this by entering n.

Fine-Tuning the VNC Startup Script

The initial run created a startup file named xstartup in a hidden .vnc directory in your home folder. By default, this file won’t launch the full Xfce desktop we just installed. We need to modify this script to tell VNC which desktop environment to load.

Step 3: Stop the Initial VNC Server Instance

The server instance we just started was only for generating the configuration. We can stop it now. It is typically running on display :1.

vncserver -kill :1

Step 4: Back Up and Create a New Startup Script

It’s always a good practice to back up the original file before making changes.

mv ~/.vnc/xstartup ~/.vnc/xstartup.bak

Now, create a new xstartup file using a text editor like nano.

nano ~/.vnc/xstartup

Step 5: Add Commands to the Startup Script

Paste the following lines into the new file. This script ensures that an Xfce session starts every time you connect.

#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
  • xrdb $HOME/.Xresources: This command loads the X server resource database settings.
  • startxfce4 &: This command starts the Xfce desktop environment. The & symbol runs it as a background process.

Save and close the file.

Step 6: Make the Script Executable

The VNC server needs permission to run the xstartup script. If this step is missed, you will likely encounter a blank gray screen when you connect.

chmod +x ~/.vnc/xstartup

The reliability of Ubuntu is a big reason why tools like VNC are so commonly paired with it. TightVNC’s presence in the official repositories has made it a go-to for remote administration, especially for distributed teams. For those interested, you can dig into more details on Ubuntu’s platform influence and market share.

This diagram shows the basic workflow we just followed.

Image

As you can see, the key is to set your password first, then make sure the startup script is configured correctly before you launch the server for regular use.

Running VNC as a Reliable System Service

Image

Manually starting your VNC server works for a quick, one-off task, but it’s not a long-term solution. The moment your server reboots or you close the SSH session, your VNC connection is gone. To make this a professional, hands-off setup, we need to run VNC as a proper system service.

By setting it up this way, we’re handing over management to Ubuntu’s own system manager, systemd. This is the key to persistence. Systemd will ensure VNC starts automatically at boot and keeps it running in the background, transforming it from a temporary tool into a dependable, always-on remote access solution.

Creating a Systemd Unit File

Our first move is to create a new service configuration file. This little text file, called a unit file, is the blueprint that tells systemd how to manage the VNC server. We need sudo since this file goes into a protected system directory.

Step 1: Create the Service File

Open a new unit file for editing using nano.

sudo nano /etc/systemd/system/[email protected]

Step 2: Add the Service Configuration

Paste the following configuration into the blank file. This template defines how systemd will start, stop, and manage the VNC service.

[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User=your_username
Group=your_username
WorkingDirectory=/home/your_username

PIDFile=/home/your_username/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Don’t forget this part: You absolutely must replace your_username with your actual Ubuntu username in all three places. This is crucial for making sure the service runs with the correct user permissions and points to the right home directory.

Managing Your New VNC Service

With the unit file saved, we just need to let systemd know about our new service. After that, we can tell it to start on boot and fire it up for the first time.

Step 3: Reload the Systemd Daemon

This command makes systemd scan for new or changed service files.

sudo systemctl daemon-reload

Step 4: Enable the Service

This tells systemd to launch the VNC service on display :1 automatically every time the server boots up.

sudo systemctl enable [email protected]

Step 5: Start the Service

This command starts the service immediately without needing to reboot.

sudo systemctl start vncserver@1

And that’s it! You now have a persistent VNC server. You can check its status anytime using sudo systemctl status vncserver@1.

Securing VNC Traffic with an SSH Tunnel

Image

While having a VNC server is incredibly convenient, leaving it open to the internet is a recipe for disaster. By default, VNC traffic isn’t encrypted, meaning your login details and entire session could be exposed. The industry-standard solution? An SSH tunnel.

Think of an SSH tunnel as a secure, private pipeline for your data. It wraps your entire VNC connection in a layer of strong SSH encryption, protecting it from anyone trying to eavesdrop on the network.

Creating the Secure Tunnel

Setting up the tunnel is surprisingly straightforward. You just need to run one command, but it’s crucial to run it from your local computer’s terminal, not the server you’re connecting to.

On Linux or macOS, use this command format:

ssh -L 5901:localhost:5901 -C -N -l your_username your_server_ip

Let’s quickly walk through what each part of that command does:

  • -L 5901:localhost:5901: Forwards traffic from port 5901 on your local machine to port 5901 on the server. This is the core of the tunnel.
  • -C: Enables compression to make the connection feel more responsive.
  • -N: Tells SSH not to execute a remote command, as we only need port forwarding.
  • -l your_username your_server_ip: Specifies your server username and IP address.

Once that tunnel is up and running, all your VNC traffic is automatically encrypted. This simple technique has become a best practice and effectively resolves the historical security concerns associated with VNC.

This method of tunneling traffic is now a foundational security measure for remote access. To dig deeper into this and other security measures, the community has put together some excellent resources, like these recommended security practices on DigitalOcean.

With the tunnel established, simply open your favorite VNC client and point it to localhost:5901. Don’t use your server’s public IP address. The SSH tunnel will securely forward the connection behind the scenes.

Troubleshooting Common VNC Problems

Getting VNC running is a great first step, but sometimes you hit a snag. Let’s walk through a few of the most common questions and issues that pop up after an initial setup, so you can get your remote desktop working perfectly.

Why Am I Staring at a Gray Screen?

Ah, the infamous gray screen. If you connect and see nothing but a blank, gray display with a cursor, it almost always means one thing: VNC started, but your desktop environment didn’t. This is a classic symptom of a problem with the ~/.vnc/xstartup file.

  • Check File Permissions: Ensure the script is executable. It’s a simple step that’s surprisingly easy to forget.chmod +x ~/.vnc/xstartup
  • Verify File Contents: Double-check your xstartup file to make sure the line startxfce4 & is present and spelled correctly. Without it, VNC doesn’t know which desktop to load.

How Can I Change the VNC Desktop Resolution?

The default resolution can feel a bit small on modern displays. The easiest way to set a custom resolution is to specify it when you start the server using the -geometry flag.

For example, this command will launch a new session at 1920×1080:

vncserver -geometry 1920x1080

Pro Tip: If you’re running VNC as a service (which is a good idea for long-term use), you’ll need to edit the [email protected] file in /etc/systemd/system/. Just find the ExecStart line and add the -geometry 1920x1080 option there to make the change permanent.

Are There Alternatives to TightVNC?

While TightVNC is a solid, lightweight choice, it’s definitely not the only game in town. Depending on what you need, another server might serve you better.

  • TigerVNC: An excellent, modern alternative that is actively maintained, performs well, and has a strong focus on security.
  • RealVNC: A commercial-grade solution with paid versions offering advanced features like end-to-end encryption and simplified cloud connections.

Your best bet is to think about what you value most—is it raw performance, ease of setup, or advanced security features? That will point you to the right server.

Can I Connect from Windows or macOS?

You absolutely can. That’s the beauty of the VNC protocol—it’s platform-agnostic. You can use any VNC client on any operating system to connect to your Ubuntu machine.

Some of the most popular viewers include:

  • RealVNC Viewer: A polished and widely used client available on all major platforms.
  • TightVNC Viewer: A simple and effective viewer that pairs well with TightVNC Server.
  • TigerVNC Viewer: A high-performance client that is a great match for TigerVNC Server.

Just install one on your local machine. When you go to connect, remember the secure SSH tunnel we set up. You’ll want to point your VNC client to localhost:5901, not your server’s public IP address.

Leave a Reply

Your email address will not be published. Required fields are marked *