Prerequisites
Ensure your Ubuntu system has a graphical desktop environment (e.g., GNOME, Xfce) installed. For server editions, install one first:
sudo apt update && sudo apt install ubuntu-desktop # For GNOME
# OR
sudo apt install xfce4 # For Xfce (lighterweight)
Update system packages and install essential tools:
sudo apt update && sudo apt upgrade -y
sudo apt install build-essential curl wget git -y
Install the TigerVNC standalone server and common components:
sudo apt install tigervnc-standalone-server tigervnc-common -y
Set a secure VNC password (different from your system login password) for authentication:
vncpasswd
TigerVNC requires a startup script (~/.vnc/xstartup) to launch the desktop environment.
Run vncserver once to create the .vnc directory and default files:
vncserver
Press Ctrl+C to stop the server immediately after creation.
Open the xstartup file in a text editor (e.g., nano):
nano ~/.vnc/xstartup
Replace the content with the following (adjust for your desktop environment):
For GNOME (default on Ubuntu Desktop):
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
xrdb $HOME/.Xresources
vncconfig -iconic &
gnome-session &
For Xfce (lightweight alternative):
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
xrdb $HOME/.Xresources
startxfce4 &
Save the file (Ctrl+O, Enter, Ctrl+X) and make it executable:
chmod +x ~/.vnc/xstartup
Launch the VNC server with a specified display number (e.g., :1 for port 5901):
vncserver :1
5901 (:1 = 5900 + 1).vncserver -list
If UFW (Uncomplicated Firewall) is enabled, allow the VNC port (default: 5901 for :1):
sudo ufw allow 5901/tcp
sudo ufw enable # Enable firewall if not already active
To ensure the VNC server starts at boot, create a systemd service file:
sudo nano /etc/systemd/system/vncserver@.service
Replace <USER> with your Ubuntu username and adjust the geometry/display settings as needed:
[Unit]
Description=Start TigerVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=<USER>
Group=<USER>
WorkingDirectory=/home/<USER>
PIDFile=/home/<USER>/.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
Reload systemd, enable the service, and start it:
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 (Windows/macOS/Linux), use a VNC client (e.g., RealVNC Viewer, TigerVNC Viewer) to connect:
192.168.1.100:1).5901 for :1). Check with netstat -tulnp | grep 5901.xstartup file has execute permissions (chmod +x ~/.vnc/xstartup) and matches your desktop environment.sudo ufw status).ssh -L 5901:localhost:5901 <USER>@<SERVER_IP>
Then connect the VNC client to localhost:1.By following these steps, you can securely share your Ubuntu desktop using TigerVNC and access it from any remote device.