Installing and Configuring VNC on Ubuntu
VNC (Virtual Network Computing) enables remote access to an Ubuntu system’s graphical desktop. Below is a structured guide to installing, configuring, and securing a VNC server on Ubuntu.
Before installing VNC software, update your system’s package list to ensure compatibility with the latest versions:
sudo apt update
For a lightweight and efficient setup, use TigerVNC (recommended) with the XFCE desktop environment (less resource-intensive than GNOME):
sudo apt install tigervnc-standalone-server tigervnc-common xfce4 xfce4-goodies -y
Configure a password for VNC authentication (required for all connections). The password must be between 6–8 characters long:
vncpasswd
~/.vnc/passwd
.Customize the ~/.vnc/xstartup
file to launch the XFCE desktop when the VNC server starts. This file defines the session environment:
nano ~/.vnc/xstartup
Replace the existing content with the following (for XFCE):
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4
unset SESSION_MANAGER
: Prevents session management conflicts.exec startxfce4
: Launches the XFCE desktop.Ctrl+O
, Enter
) and exit (Ctrl+X
).chmod +x ~/.vnc/xstartup
Launch the VNC server with a specified display number (e.g., :1
). The display number corresponds to a TCP port (5900 + display number; :1
= port 5901):
vncserver :1 -geometry 1920x1080 -depth 24
:1
: Display number (adjust as needed, e.g., :2
for port 5902).-geometry 1920x1080
: Sets the remote desktop resolution.-depth 24
: Configures color depth (24-bit for full color).If your Ubuntu system uses UFW (Uncomplicated Firewall), allow traffic to the VNC port (default: 5901 for :1
):
sudo ufw allow 5901/tcp
sudo ufw reload
sudo ufw status
To ensure the VNC server starts automatically after a system reboot, create a Systemd service file:
sudo nano /etc/systemd/system/vncserver@.service
Add the following content (replace your_username
with your actual username and :1
with your display number):
[Unit]
Description=VNC Server for user %u at display %i
After=network.target
[Service]
Type=simple
User=your_username
WorkingDirectory=/home/your_username
ExecStartPre=/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1920x1080 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
Save and exit. Then, enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service # Replace "1" with your display number
sudo systemctl start vncserver@1.service
On a remote computer, use a VNC client (e.g., RealVNC, TightVNC, or TigerVNC Viewer) to connect to your Ubuntu system:
192.168.1.100:5901
for :1
).~/.vnc/xstartup
has executable permissions (chmod +x ~/.vnc/xstartup
) and uses the correct desktop environment (e.g., startxfce4
for XFCE).sudo netstat -tulnp | grep 5901
.sudo ufw status
) to confirm port 5901 is allowed.-geometry
parameter in the vncserver
command (e.g., 1280x720
for smaller screens).This guide provides a secure and functional VNC setup for Ubuntu, enabling remote desktop access with minimal overhead. For advanced security (e.g., SSH tunneling), consider encrypting VNC traffic using SSH to prevent unauthorized access.