Setting up remote access for Ubuntu servers or workstations is a common requirement for system administrators and home users alike. Virtual Network Computing (VNC) provides a graphical solution for controlling a machine from another location, which is essential when a graphical user interface is needed without a physical monitor. This guide walks through the entire process of how to install VNC on Ubuntu, ensuring a stable and secure connection.
Understanding VNC and Its Role
VNC operates on a client-server model, where the server shares its display output and the client allows you to interact with it remotely. Unlike SSH, which provides a command-line interface, VNC transmits the graphical desktop environment. This makes it ideal for troubleshooting, managing software, or accessing a full desktop session. For Ubuntu users, the most compatible and modern choice is TigerVNC, which offers improved performance and security over older alternatives.
Preparing the Ubuntu Server
Before installing the VNC server, it is best to ensure the target machine is ready. This involves updating the package index and upgrading existing software to patch any known vulnerabilities. Performing this step ensures stability and reduces potential conflicts during the VNC installation process. A clean system provides a reliable foundation for the remote desktop environment.
System Update and Upgrade
Log into your Ubuntu machine via SSH and execute the following commands to synchronize with the repository and apply updates:
sudo apt update
sudo apt upgrade -y
Installing the Desktop Environment
Ubuntu Server installations often omit a graphical interface to conserve resources. VNC requires a desktop environment to share, so you must install one before proceeding. XFCE is a highly recommended lightweight option due to its low resource consumption and stability. It provides a modern interface without the overhead of larger environments like GNOME.
Installing XFCE
Run the following command to install the XFCE desktop environment and the necessary utilities:
sudo apt install xfce4 xfce4-goodies git -y
This installation might take a few minutes depending on your connection speed and system resources. Once completed, you will have the necessary graphical components for the VNC server to transmit.
Installing TigerVNC Server
With the desktop environment in place, the next step is to install the VNC server software. TigerVNC is available in the default Ubuntu repositories, making the installation straightforward. Selecting the correct package ensures you receive a version that integrates well with the XFCE desktop.
VNC Server Installation
Execute the following command to install the TigerVNC server:
sudo apt install tigervnc-standalone-server -y
After the installation, verify the binary is available by checking the version, which confirms a successful setup.
Configuring VNC Password and Startup Script
Security is paramount when exposing a graphical interface over the network. You must set a dedicated VNC password that differs from your system login credentials. Additionally, you need to configure the startup script to ensure the VNC server launches the XFCE session correctly upon connection.
Setting the VNC Password
Run the vncpasswd command and follow the prompts to create a password. Store this password securely, as it is required for every client connection.
Creating the Startup Script
Create a file named ~/.vnc/xstartup to define the desktop environment. Use a text editor to insert the following configuration:
#!/bin/bash
xrdb $HOME/.Xresources