Tips&Tricks

How to Install VNC Server on Ubuntu: The Complete Guide

Setting up a VNC Server on Ubuntu opens the door to remote graphical desktop access, making server management and troubleshooting a breeze—even from across the globe. Whether you’re a developer, system admin, or just want to access your Ubuntu machine from your laptop or phone, this detailed, step-by-step guide will walk you through everything you need to know. Let’s get started!

Also Read:
How to Play PC Games on a TV
How to Make an App Portable
How to Change Port on CasaOS
How to Redirect SMS to Email
Why Did My Firestick Stop Working?

What is VNC Server?

What is VNC Server

VNC (Virtual Network Computing) is a remote desktop protocol that lets you control another computer’s desktop environment over a network. With a VNC Server running on your Ubuntu machine, you can interact with its graphical interface from anywhere using a VNC client. This is ideal for managing servers, providing remote support, or just accessing your files and apps when you’re not physically at your computer.

Prerequisites

Before you dive in, make sure you have:

  • An Ubuntu server or desktop (Ubuntu 20.04, 22.04, or newer recommended)
  • A user account with sudo privileges
  • Internet connectivity
  • A VNC client on your local machine (like RealVNC Viewer, TigerVNC Viewer, or TightVNC Viewer)

Here’s a quick comparison of system requirements:

RequirementMinimumRecommended
Ubuntu Version18.04+20.04/22.04 LTS
RAM1 GB2 GB+
CPU1 Core2+ Cores
Disk Space10 GB20 GB+
User PrivilegesSudo userSudo user

Choosing the Right VNC Server for Ubuntu

Ubuntu supports several VNC server options. Here’s a quick rundown:

VNC ServerProsConsBest For
TigerVNCFast, open-source, multi-platformManual security configurationLinux power users
TightVNCLightweight, easy to set upFewer enterprise featuresHome/SMB users
RealVNCFeature-rich, enterprise securityPaid for full featuresBusinesses, teams
x11vncShares existing X sessionNot as robust for multiple usersSharing live session

For most users, TightVNC or TigerVNC paired with the Xfce desktop environment is a sweet spot for performance and simplicity.

Update and Prepare Your Ubuntu System

Let’s make sure your system is ready for the installation:

  1. Open a terminal (Ctrl+Alt+T or via SSH).
  2. Update your package list: bashsudo apt update sudo apt upgrade
  3. Install essential tools (optional): bashsudo apt install wget curl nano

Installing a VNC Server on Ubuntu

We’ll use TightVNC in this example, but the steps are similar for other servers.

Installing a VNC Server on Ubuntu

Step 1: Install the Desktop Environment

If your Ubuntu is running in headless mode (no GUI), you’ll need a desktop environment. Xfce is lightweight and ideal for remote sessions.

bashsudo apt install xfce4 xfce4-goodies

This installs the Xfce desktop and additional tools for a smoother experience.

Step 2: Install the VNC Server

bashsudo apt install tightvncserver

This command grabs the TightVNC Server from Ubuntu’s repositories.

Configuring the VNC Server

Step 1: Set the VNC Password

Start the VNC server for the first time to set your password:

bashvncserver
  • You’ll be prompted to enter a password (6-8 characters).
  • Optionally, set a view-only password for restricted access.

To change the password later:

bashvncpasswd

Step 2: Stop the VNC Server to Configure

Before customizing, stop the running VNC session:

bashvncserver -kill :1

Here, :1 is the display number (port 5901).

Step 3: Configure the Desktop Environment

Back up the original startup script:

bashmv ~/.vnc/xstartup ~/.vnc/xstartup.bak

Create a new xstartup file:

bashnano ~/.vnc/xstartup

Paste the following:

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

Save and exit (Ctrl+O, Enter, Ctrl+X).

Make it executable:

bashchmod +x ~/.vnc/xstartup

Setting Up the Desktop Environment

You can use other desktop environments like GNOME or KDE Plasma, but Xfce is recommended for speed and resource efficiency. If you want to try another, install it with:

  • GNOME: bashsudo apt install ubuntu-desktop
  • KDE Plasma: bashsudo apt install kde-plasma-desktop

Set your preferred desktop as the default X session:

bashsudo update-alternatives --config x-session-manager

Starting and Managing the VNC Server

Start the VNC Server

bashvncserver

This launches a new session (e.g., :1 for port 5901).

Manage VNC Sessions

ActionCommand
Startvncserver
Stopvncserver -kill :1
List sessions`ps -ef

Auto-Start VNC at Boot

To run VNC automatically at system startup, add the following to /etc/rc.local before exit 0:

bashsu - your_username -c '/usr/bin/vncserver :1'

Or, configure a systemd service for more robust management.

Connecting to the VNC Server

Step 1: Install a VNC Client

On your local machine, install a VNC client like RealVNC Viewer, TigerVNC Viewer, or TightVNC Viewer.

Step 2: Find Your Ubuntu Server’s IP Address

bashhostname -I

Step 3: Connect

Open your VNC client and enter:

textyour_server_ip:5901

or

textyour_server_ip:1
  • Enter the password you set earlier.
  • You should see your Ubuntu desktop!

Securing Your VNC Connection

VNC traffic is not encrypted by default. For secure remote access, tunnel your connection through SSH.

How to Set Up SSH Tunneling

  1. On your local machine, run: bashssh -L 5901:localhost:5901 your_username@your_server_ip
  2. Connect your VNC client to: textlocalhost:5901

This ensures all VNC traffic is encrypted between your device and the server.

Firewall Configuration

Allow only local connections to the VNC port and block remote access at the firewall:

bashsudo ufw allow from 127.0.0.1 to any port 5901

Security Best Practices Table

PracticeDescription
SSH TunnelingEncrypts VNC traffic
Strong PasswordsUse complex, unique passwords
Firewall RulesRestrict VNC port to localhost only
UpdatesRegularly update VNC and OS

Advanced Configuration and Tips

  • Multiple Users/Sessions: Each user can run their own VNC session on a different port (e.g., vncserver :2 for port 5902).
  • Custom Ports: Specify a different display number to avoid conflicts.
  • Performance Tuning: Lower the desktop resolution or color depth for faster connections.
  • Logging: Check ~/.vnc/*.log files for troubleshooting.

Troubleshooting Common Issues

Here’s a handy table for common problems and solutions:

ProblemSolution
Connection refusedCheck if VNC server is running; verify firewall rules
Black screenEnsure desktop environment is installed and configured in xstartup
Port conflictUse a different display number (e.g., :2 for 5902)
Authentication errorsReset password with vncpasswd
Session not startingCheck logs in ~/.vnc/ and verify xstartup script
Cloud connection issues (RealVNC)Enable cloud connectivity in RealVNC settings

Uninstalling or Disabling VNC Server

Uninstalling or Disabling VNC Server

To remove TightVNC:

bashsudo apt remove --purge tightvncserver
sudo rm -rf ~/.vnc

Clean up any desktop environment if not needed:

bashsudo apt remove --purge xfce4 xfce4-goodies

Frequently Asked Questions

Q1 : Can I use VNC with other desktop environments?

A: Yes! Install your preferred environment and update the xstartup script accordingly.

Q2 : Is VNC secure?

A: Not by default. Always use SSH tunneling and strong passwords.

Q3 : Can multiple users connect at once?

A: Yes, each user can start their own VNC session on a unique port.

Q4 : How do I change my VNC password?

A: Use the vncpasswd command.

Conclusion

Setting up a VNC Server on Ubuntu is a fantastic way to unlock remote desktop access and manage your system from anywhere. By following this guide, you’ve learned how to install, configure, secure, and troubleshoot your VNC setup. Whether you’re using TightVNC, TigerVNC, or RealVNC, the process is straightforward and adaptable to your needs.

Nitu Dudhpachare

Hi, I’m Nitu Dudhpachare, senior writer at Insiderup.com and a firm believer in free thinking and honest expression. I write to inspire, challenge perspectives, and help people reconnect with their inner strength. My goal is simple — to spark real thoughts and real change through every piece I create.

Related Articles

Leave a Reply

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

Back to top button