Installing a VNC Server on Ubuntu: A Step-by-Step Guide
VNC (Virtual Network Computing) enables remote access to your Ubuntu system’s graphical desktop. Below is a structured guide to installing and configuring a VNC server on Ubuntu, optimized for reliability and security.
Before installing software, refresh your system’s package repository to ensure you get the latest versions:
sudo apt update && sudo apt upgrade -y
For Ubuntu, the recommended VNC server is TigerVNC (or tightvncserver
for lightweight needs). Install it along with a desktop environment (e.g., XFCE for better performance on servers):
# Install TigerVNC server and XFCE desktop (replace with your preferred desktop)
sudo apt install tigervnc-standalone-server tigervnc-common xfce4 xfce4-goodies -y
ubuntu-desktop
if you prefer the default GNOME environment.tigervnc-common
provides essential utilities for VNC configuration.Configure a password for VNC access (required for all connections). The password must be 6–8 characters long:
vncpasswd
~/.vnc/passwd
.Edit the ~/.vnc/xstartup
file to define the desktop environment launched when connecting via VNC. For XFCE:
nano ~/.vnc/xstartup
Replace the file’s content with:
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4
Ctrl+O
, Enter
, Ctrl+X
) and make the file executable:chmod +x ~/.vnc/xstartup
For automatic startup at boot and easier management, create a systemd service:
sudo nano /etc/systemd/system/vncserver@:1.service
Add this configuration (replace your_username
with your actual username):
[Unit]
Description=Start TigerVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=your_username
PAMName=login
PIDFile=/home/your_username/.vnc/%H:1.pid
ExecStartPre=-/usr/bin/vncserver -kill :1 > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1920x1080 :1
ExecStop=/usr/bin/vncserver -kill :1
[Install]
WantedBy=multi-user.target
-depth 24
: Sets color depth (24-bit for best quality).-geometry 1920x1080
: Defines screen resolution. Adjust to your preference.Reload systemd to apply the new service, then start and enable the VNC server:
# Reload systemd to recognize the new service
sudo systemctl daemon-reload
# Start the VNC server (display :1 = port 5901)
sudo systemctl start vncserver@:1.service
# Enable auto-start at boot
sudo systemctl enable vncserver@:1.service
sudo systemctl status vncserver@:1.service
If your Ubuntu system uses UFW (Uncomplicated Firewall), allow traffic to the VNC port (default: 5901 for display :1):
sudo ufw allow 5901/tcp
sudo ufw reload
:2
), adjust the port to 5902
(5900 + display number).Use a VNC client (e.g., TigerVNC Viewer, RealVNC, or Remmina) on your local machine. Enter the server’s IP address and port (e.g., 192.168.1.100:5901
) and authenticate with the password set in Step 3.
~/.vnc/xstartup
is correctly configured and executable.sudo systemctl status vncserver@:1.service
) and the firewall allows the port.-geometry
parameter in the systemd service or vncserver
command.By following these steps, you’ll have a secure and functional VNC server on Ubuntu, enabling remote access to your desktop environment from any compatible client.