Skip to content

Instantly share code, notes, and snippets.

@SHJordan
Last active January 2, 2026 14:48
Show Gist options
  • Select an option

  • Save SHJordan/09e0298cd54f2adc2e72f9a07ec1f97b to your computer and use it in GitHub Desktop.

Select an option

Save SHJordan/09e0298cd54f2adc2e72f9a07ec1f97b to your computer and use it in GitHub Desktop.
Setup Ubuntu Desktop (XFCE4) on WSL2 via RDP

Setup Ubuntu Desktop (XFCE4) on WSL2 via RDP

This guide covers how to install the XFCE4 desktop environment on WSL2 (Ubuntu) and connect to it using Windows Remote Desktop.

It specifically addresses two common issues on WSL2:

  1. Black Screen: Caused by incorrect color depth settings.
  2. Session Closing Immediately: Caused by conflicts between XRDP and WSLg environment variables (DBUS / XDG).

1. Update and Install Packages

Open your WSL2 terminal and run the following to install XRDP and the XFCE4 environment.

# Update repositories
sudo apt update && sudo apt -y upgrade

# Install XRDP
sudo apt -y install xrdp

# Install XFCE4 and recommended utilities (goodies)
# Note: 'goodies' is recommended for a better experience (terminal, icons, etc.)
sudo apt -y install xfce4 xfce4-goodies

2. Configure XRDP

We need to change the default RDP port (to avoid conflict with Windows) and ensure the color depth is compatible.

# Backup the original configuration
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak

# Change port from 3389 to 3390
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini

# Ensure max_bpp is set to 32 (Setting this to 128 causes a black screen)
sudo sed -i 's/max_bpp=128/max_bpp=32/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/xserverbpp=128/xserverbpp=32/g' /etc/xrdp/xrdp.ini

3. Configure the Session

Tell the system to use XFCE4 when a remote session starts.

echo "startxfce4" > ~/.xsession

4. Fix WSL2/WSLg Incompatibility (Critical Step)

By default, WSL2 passes Windows environment variables to Linux. This confuses XFCE when running via XRDP, causing the RDP window to close immediately after login.

We must edit the startup script to unset these variables.

  1. Open the startup script:
sudo nano /etc/xrdp/startwm.sh
  1. Replace the entire content of the file with the following script:
#!/bin/sh

# Load essential paths
if [ -r /etc/profile ]; then . /etc/profile; fi

# UNSET WSLg VARIABLES
# These lines prevent conflicts with the Windows display system
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR

# Start XFCE
startxfce4
  1. Save and exit (Ctrl+O, Enter, Ctrl+X).

5. Restart XRDP and Connect

Restart the service to apply changes:

sudo service xrdp restart

How to Connect:

  1. Open Remote Desktop Connection on Windows.
  2. Computer: localhost:3390
  3. Enter your WSL2 username and password.

Troubleshooting

If you are stuck at a login loop or the window still closes:

  1. Clear old session locks:
rm ~/.Xauthority
rm ~/.xsession-errors
  1. Restart the service again:
sudo service xrdp restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment