This tutorial explains how to set up an xRDP server on Ubuntu 18.04 using the lightweight Xfce desktop environment, allowing remote access from Windows via the RDP protocol. It’s a practical solution for anyone who needs to connect to a Linux system with a graphical interface using Remote Desktop.
What is xRDP?
xRDP is Microsoft's free and open-source implementation of RDP (Remote Desktop Protocol) which allows non-Microsoft Windows operating systems (such as Linux and BSD) to provide a fully functional RDP-compatible remote desktop.
Installation and Setup
Connect to your ubuntu server via SSH and perform a system update:
sudo apt-get update
sudo apt-get upgrade -y
Install and enable the xRDP utility:
sudo apt-get install xrdp
sudo systemctl enable xrdp
sudo systemctl restart xrdp

Install the xfce environment:
sudo apt-get install xfce4 xfce4-terminal
Open RDP port to be able to connect remotely:
sudo ufw allow 3389/tcp
Reboot the xRDP server for the changes to take effect:
sudo /etc/init.d/xrdp restart
Connecting to an Ubuntu Server via RDP
If you don't know the IP address of the Ubuntu server, you can check it by entering the command:
ifconfig -a

In our test case it is 10.0.0.2. To connect open the Windows Remote Desktop Connection (mstsc.exe). Enter the IP address of the server and click Connect:

A security warning will appear. Click Yes:

In the opened window, select Xorg as the session, enter the username and password for the user and click OK:
Attention: If you are connecting via xRDP, you need to specify a password and root user name. If you are connecting via SSH, you will need the key or password that was configured during the creation of the server in the cloud.

This will connect to the xforce desktop.

If it shows a black screen when connecting to xrdp you need to go into the /etc/xrdp folder, and make changes to the startwm.sh file.
sudo nano /etc/xrdp/startwm.sh
We need to add:
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR
Before the line:
test -x /etc/X11/Xsession && exec /etc/X11/Xsession

After making the changes you have to restart the XRDP service:
sudo systemctl restart xrdp
Now you can run mstsc.exe again and connect to our ubuntu server.
FAQ: What should I do if I see a black screen after connecting via xRDP?
A black screen on connection usually means the desktop environment isn't launching properly. To fix this, edit the startwm.sh file located in /etc/xrdp/ by adding the following lines before the exec call:
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR
These lines help ensure proper environment variables are set when starting the session. After making changes, restart the xRDP service:
sudo systemctl restart xrdp
This should resolve the black screen issue and allow you to load the Xfce desktop environment successfully.