Setting Up XRDP Remote Desktop for Ubuntu Virtual Machines in Hyper-V
Hyper-V Session Mode
When configuring Ubuntu inside Hyper-V, use Basic Session. Enhanced Session is incompatible with XRDP and causes display errors.
System Preparation
Refresh package indexes and install upgrades:
sudo apt update
sudo apt upgrade -y
If apt update times out, replace the contents of /etc/apt/sources.list with the following archive entries for Ubuntu 20.04:
deb http://us.archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu focal-security main restricted universe multiverse
Then rerun the update command.
Install XRDP:
sudo apt install xrdp -y
XRDP Startup Configuration
To prevent the black-screen or immediate-disconnect issue, modify /etc/xrdp/startwm.sh:
sudoedit /etc/xrdp/startwm.sh
Replace the file with the following script:
#!/bin/bash
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_CONFIG_HOME="$HOME/.config"
mkdir -p "$XDG_CACHE_HOME" "$XDG_CONFIG_HOME"
exec startxfce4
Save and close the editor.
Service Permissions
Grant the XRDP daemon access to SSL certificate files:
sudo usermod --append --groups ssl-cert xrdp
Enable the service to start on boot and restart it immediately:
sudo systemctl enable xrdp
sudo systemctl restart xrdp
Confirm the daemon state:
sudo systemctl status xrdp
A control process exited error usual resolves after a full system reboot.
Firewall Configuration
Allow port 3389 through UFW. For unrestrictde access:
sudo ufw allow 3389/tcp
For a restricted LAN segment (example: 192.168.1.0/24):
sudo ufw allow proto tcp from 192.168.1.0/24 to any port 3389
sudo ufw reload
Windows Client Connection
On the Windows machine, launch the Remote Desktop client:
mstsc
Connect to the Ubuntu guest IP. On first contact, accept the unknown-host warning. At the authentication prompt, enter a valid Ubuntu local account.
If the login is rejected, open the Ubuntu desktop, go to Settings > Sharing > Remote Desktop, and reconfigure the access password.
Optional Desktop Environment Installation
If no GUI is present, install a desktop environment before setting up XRDP:
sudo apt install tasksel
sudo tasksel
# Choose Ubuntu Desktop in the interface
sudo systemctl set-default graphical.target
sudo reboot
After the guest restarts, complete the XRDP configuration steps above.