Ubuntu Remote Desktop (GUI)
Ubuntu Server does not include a graphical interface by default. However, you can install one and connect to it remotely using VNC or RDP. This guide covers both methods.
Do not expose ports 5901 (VNC) or 3389 (RDP) directly to the internet. Use an SSH tunnel, WireGuard, or another VPN solution to secure the connection. If you must allow these ports through the firewall, restrict access to trusted IP ranges only.
For most production Ubuntu servers, the recommended combination is: Xfce desktop environment, xrdp for remote access, and WireGuard or an SSH tunnel for secure connectivity.
What you need
- Ubuntu server (20.04 / 22.04 / 24.04)
- Root or sudo access
- A client computer (Windows or macOS) to connect from
Install a desktop environment
Update the package list:
apt update && apt upgrade -y
Install the minimal GNOME desktop:
apt install ubuntu-desktop-minimal -y
For production servers, Xfce is generally recommended — it uses fewer resources and works more reliably over VNC and xrdp:
apt install xfce4 xfce4-goodies -y
After the installation completes, set the default boot target to graphical mode and reboot:
systemctl set-default graphical.target reboot
The systemctl set-default graphical.target command permanently changes the default boot mode so the graphical environment starts automatically after every reboot. On a headless server where you only need remote desktop access, you can skip this step and just reboot.
Option 1. Connect via VNC
VNC (Virtual Network Computing) lets you view and control the desktop remotely. This section uses TigerVNC.
Install TigerVNC server
apt install tigervnc-standalone-server tigervnc-common -y
Create a VNC user
Run VNC as a non-root user. Create one if you do not have one already:
adduser vncuser
Do not add the VNC user to the sudo group. If an attacker gains access to the VNC session, sudo access would give them full control over the server.
Switch to that user:
su - vncuser
Set a VNC password
vncpasswd
Enter and confirm a password. When asked "Would you like to enter a view-only password?", enter n.
VNC requires an Xorg backend. On Ubuntu 24.04, GNOME runs on Wayland by default. If you plan to use VNC with GNOME, disable Wayland first as described in the xrdp section below (WaylandEnable=false in /etc/gdm3/custom.conf). Without this, you may get a black screen.
On Ubuntu 24.04, dbus-launch may not be installed by default. If you get a "command not found" error when starting the VNC session, install it first: apt install dbus-x11 -y
Configure the VNC session
Create the config directory and startup file:
mkdir -p ~/.vnc nano ~/.vnc/xstartup
Paste the following:
#!/bin/bash export XDG_SESSION_TYPE=x11 export GNOME_SHELL_SESSION_MODE=ubuntu unset DBUS_SESSION_BUS_ADDRESS unset XDG_RUNTIME_DIR exec dbus-launch --exit-with-session gnome-session --session=ubuntu
If you installed Xfce instead of GNOME, replace the last line with: exec startxfce4
Make the file executable:
chmod +x ~/.vnc/xstartup
Start the VNC server
vncserver :1 -geometry 1920x1080 -depth 24
This starts a VNC session on display :1 (port 5901). Display :2 would use port 5902, and so on.
To stop the server:
vncserver -kill :1
Open the firewall port
ufw allow 5901/tcp
If possible, restrict access to a specific IP range instead of allowing all sources: ufw allow from 192.168.1.0/24 to any port 5901 proto tcp
Connect from Windows
Download and install TightVNC or RealVNC Viewer.
Open the client and enter: your-server-ip:5901
[IMAGE: vnc-connect-address.png — RealVNC Viewer with the server address entered]
Enter the VNC password when prompted. Once connected, you will see the remote desktop:
[IMAGE: vnc-xfce-desktop.png — the remote desktop shown over VNC]
Connect from macOS
macOS includes a built-in VNC client. Open Finder, press Cmd+K, and enter:
vnc://your-server-ip:5901
Enter the password when prompted.
VNC traffic is not encrypted by default. Tunnel the connection through SSH: ssh -L 5901:localhost:5901 user@your-server-ip, then connect to localhost:5901 from your VNC client.
Option 2. Connect via RDP
RDP (Remote Desktop Protocol) is the standard protocol used by Windows Remote Desktop. On Ubuntu, it is provided by the xrdp package.
GNOME sessions over xrdp may be unstable on some Ubuntu releases, especially when Wayland is enabled. Xfce generally provides a more reliable remote desktop experience.
Disable Wayland
xrdp requires an Xorg backend. Open the GDM configuration file:
nano /etc/gdm3/custom.conf
Find the line #WaylandEnable=false, uncomment it and save the file:
WaylandEnable=false
Install xrdp
apt install xrdp -y
Enable and start the service:
systemctl enable --now xrdp
Add xrdp user to the ssl-cert group
adduser xrdp ssl-cert
Configure the session startup file
Open /etc/xrdp/startwm.sh and add the following lines before the final exec line:
export XDG_SESSION_TYPE=x11 export GNOME_SHELL_SESSION_MODE=ubuntu unset DBUS_SESSION_BUS_ADDRESS unset XDG_RUNTIME_DIR
Open the firewall port
ufw allow 3389/tcp
If possible, restrict access to a specific IP range: ufw allow from 192.168.1.0/24 to any port 3389 proto tcp
Restart xrdp
systemctl restart xrdp
Connect from Windows
Press Win+R, type mstsc, press Enter. Enter your server IP address and click Connect.
[IMAGE: mstsc-connection-dialog.png — Remote Desktop Connection with the server address entered]
At the xrdp login screen, leave the session as Xorg and enter your Ubuntu username and password:
[IMAGE: xrdp-login.png — the xrdp login screen]
After logging in, the remote desktop appears:
[IMAGE: rdp-xfce-desktop.png — the remote desktop shown over RDP]
Connect from macOS
Install Microsoft Remote Desktop from the App Store.
Click Add PC, enter your server IP address.
Log in with your Ubuntu username and password.
Comparison: VNC vs RDP
| VNC | RDP | |
|---|---|---|
| Protocol | Open standard | Microsoft (open-source implementation via xrdp) |
| Windows client | Third-party required | Built-in (mstsc) |
| macOS client | Built-in (Finder) | Microsoft Remote Desktop (App Store) |
| Encryption | None by default (use SSH tunnel) | TLS (handled by xrdp) |
| Performance | Moderate | Generally smoother |
| Multi-user support | Limited | Better |
Troubleshooting
Black screen after RDP login — make sure the required environment variables are added to /etc/xrdp/startwm.sh as described above, and that Wayland is disabled in /etc/gdm3/custom.conf. Then restart xrdp: systemctl restart xrdp
VNC connection refused — check that the VNC server is running: vncserver -list. Make sure port 5901 is open in the firewall.
VNC session fails to start — kill the session and clear lock files, then restart:
vncserver -kill :1 rm -f ~/.vnc/*.log ~/.vnc/*.pid vncserver :1
Connection drops or grey screen after entering password in xrdp — create or edit ~/.xsessionrc for the user and add:
export XDG_SESSION_TYPE=x11
Also make sure the user is not logged into a local desktop session at the same time — log out of the local session before connecting via xrdp.
Authentication error in xrdp — make sure you are logging in with a valid Ubuntu system user and password, not the VNC password.
xrdp connects but immediately disconnects — check the status of both services:
systemctl status xrdp systemctl status xrdp-sesman
Cannot start GNOME over VNC — on Ubuntu 24.04, you may need to install the xorg package separately: apt install xorg -y