How to Install and Configure XRDP on Ubuntu 22.04 — Full Guide (2025)

Remote desktop access is a core skill for any Linux sysadmin or network engineer. Whether you’re managing a headless Ubuntu server, supporting end users, or accessing your lab machine from home — XRDP gives you a full GUI session over the standard RDP protocol (port 3389), which means you can connect from Windows, Linux, or macOS using any RDP client.

This guide covers everything from a clean install to fixing the most common issues including the dreaded black screen after login.

Prerequisites

  • Ubuntu 22.04 LTS (desktop or server with a GUI installed)
  • A user account with
    sudo
    privileges
  • SSH or physical access to run the initial commands
  • RDP client: Windows has one built-in (mstsc), Linux use Remmina, macOS use Microsoft Remote Desktop from the App Store

Step 1 — Update Your System

Always start with a full system update before installing new packages:


sudo apt update && sudo apt upgrade -y

Step 2 — Install a Desktop Environment (if needed)

If you’re on Ubuntu Server (no GUI), you need to install a desktop environment first. Xfce is the recommended choice for XRDP — it’s lightweight, stable, and works perfectly over RDP:


sudo apt install xfce4 xfce4-goodies -y

If you already have Ubuntu Desktop (GNOME) installed, skip this step — but be aware GNOME over XRDP requires extra configuration covered in the troubleshooting section below.

Step 3 — Install XRDP


sudo apt install xrdp -y

Verify it installed correctly:


xrdp --version

Step 4 — Enable and Start the XRDP Service


sudo systemctl enable xrdp
sudo systemctl start xrdp

Confirm it’s running:


sudo systemctl status xrdp

You should see

Active: active (running)
in green. If not, jump to the troubleshooting section.

Step 5 — Configure the Session Manager (Critical Step)

This is the step most guides skip — and it causes the black screen issue. You need to tell XRDP which desktop environment to launch when a user connects.

Create or edit the

.xsession
file in your home directory:


echo "xfce4-session" > ~/.xsession

If you’re using a different desktop environment, replace

xfce4-session
with:

  • GNOME:
    gnome-session
  • KDE Plasma:
    startplasma-x11
  • MATE:
    mate-session

Step 6 — Configure the Firewall

Allow RDP traffic through UFW. For a tighter security posture, restrict it to your specific management IP instead of

any
:


# Allow from anywhere (lab/home use)
sudo ufw allow 3389/tcp

# Recommended: Allow only from your specific IP (production use)
sudo ufw allow from 192.168.1.0/24 to any port 3389 proto tcp

# Apply and verify
sudo ufw reload
sudo ufw status

Step 7 — Add XRDP User to SSL Group

This fixes a common certificate warning and session issue:


sudo adduser xrdp ssl-cert
sudo systemctl restart xrdp

Step 8 — Connect from Your Client

First, get your Ubuntu machine’s IP address:


ip addr show | grep "inet " | grep -v 127.0.0.1

Then connect from your client:

  • Windows: Press
    Win + R
    → type
    mstsc
    → Enter the Ubuntu IP → Connect
  • Linux: Open Remmina → New connection → Protocol: RDP → Enter IP
  • macOS: Open Microsoft Remote Desktop → Add PC → Enter IP

At the XRDP login screen, enter your Ubuntu username and password. Select Xorg as the session type.

Troubleshooting Common Issues

🔴 Black Screen After Login

This is the #1 XRDP problem. Causes and fixes:

Fix 1 — Missing .xsession file (most common cause):


echo "xfce4-session" > ~/.xsession
sudo systemctl restart xrdp

Fix 2 — Conflicting local session: If you’re already logged into the physical machine with the same user, XRDP will get a black screen. Log out of the local session first, then reconnect via RDP.

Fix 3 — Wrong session type in XRDP login screen: At the XRDP login screen, make sure “Session” is set to Xorg, not Xvnc.

🔴 XRDP Service Fails to Start

Check the logs for the exact error:


sudo journalctl -u xrdp -n 50 --no-pager

Common cause: port 3389 already in use. Check what’s using it:


sudo ss -tlnp | grep 3389

🔴 Connection Refused / Timeout


# Check XRDP is listening on 3389
sudo ss -tlnp | grep xrdp

# Check firewall is allowing the port
sudo ufw status verbose

# Test from the server itself
telnet localhost 3389

🔴 Authentication Failed

Make sure you’re using your Linux system password (not a Microsoft account password). If your Ubuntu account uses SSO or a keyring, reset the local password:


sudo passwd your_username

🔴 Slow or Laggy Session

XRDP performance depends on your network and desktop environment. Tips to improve speed:

  • Use Xfce instead of GNOME — significantly less resource-intensive over RDP
  • In your RDP client, reduce color depth to 16-bit
  • Disable desktop composition/animations in Xfce settings
  • If on a WAN, consider using a VPN + SSH tunnel to reduce latency

Security Hardening Tips

Never expose RDP (port 3389) directly to the internet. It’s one of the most-scanned ports by attackers. Recommended approach for production use:

  • Use a VPN or SSH tunnel — only expose RDP on localhost, then tunnel through SSH:
    ssh -L 3389:localhost:3389 user@server
  • Restrict firewall rules to known management IP ranges only
  • Enable fail2ban to block brute-force attempts on port 3389
  • Change the default RDP port from 3389 to a non-standard port in
    /etc/xrdp/xrdp.ini
  • Use strong passwords or SSH key-based authentication for your Linux accounts

Quick Reference: XRDP Commands

TaskCommand
Install XRDP
sudo apt install xrdp -y
Start service
sudo systemctl start xrdp
Stop service
sudo systemctl stop xrdp
Restart service
sudo systemctl restart xrdp
Check status
sudo systemctl status xrdp
Enable on boot
sudo systemctl enable xrdp
Check logs
sudo journalctl -u xrdp -n 50
Check port
sudo ss -tlnp | grep 3389
Allow firewall
sudo ufw allow 3389/tcp
Fix black screen
echo "xfce4-session" > ~/.xsession

Conclusion

XRDP is a reliable, free solution for remote desktop access to Ubuntu machines. The key to a smooth setup is getting the session manager configured correctly and keeping the service locked down with proper firewall rules. For any production environment, always tunnel RDP through a VPN or SSH — never expose port 3389 to the internet directly.

If you’re managing multiple Ubuntu servers remotely, check out my consulting services for infrastructure design and remote management solutions.

Scroll to Top