In this guide, we want to teach you to Install and Configure XRDP on Ubuntu 22.04.
xrdp is a free and open-source implementation of the Microsoft RDP (Remote Desktop Protocol) server that enables operating systems other than Microsoft Windows (such as Linux and BSD-style operating systems) to provide a fully functional RDP-compatible remote desktop experience.
Install and Configure XRDP on Ubuntu 22.04
Before you start to install xrdp on Ubuntu 22.04, you need to log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our article the Initial Server Setup with Ubuntu 22.04.
Now follow the steps below to complete this guide.
Install Desktop environment
XRDP server is designed to control only desktop systems. The Desktop environment is not available on Ubuntu by default. You need to add a Desktop environment to your system.
First of all, update and upgrade your local package index with the following command:
sudo apt update && sudo apt upgrade
Then, install the Tasksel utility to install a Desktop environment on Ubuntu 22.04 with the following command:
sudo apt install tasksel -y
Now you need to launch the Tasksel with the following command:
You will see the package configuration:
Find the Ubuntu desktop by using the arrow keys. Press space to select it and then press tab to select ok and hit enter to install the Ubuntu desktop.
Now you need to set your system boots into the graphical target. you can use the following command:
systemctl set-default graphical.target
Then, you need to reboot your system to apply these changes.
After that, Let’s start to install XRDP.
Install XRDP on Ubuntu 22.04
The XRDP packages are available in the Ubuntu 22.04 default repository. To install it you can use the following command:
sudo apt install xrdp -y
When your installation is finished, verify that you have installed it successfully with the following command:
sudo systemctl status xrdp
In your output you should see:
Output xrdp.service - xrdp daemon Loaded: loaded (/lib/systemd/system/xrdp.service; enabled; vendor preset: enabled) Active: active (running) Docs: man:xrdp(8) man:xrdp.ini(5) Main PID: 3108 (xrdp) Tasks: 1 (limit: 2273) Memory: 1.2M CGroup: /system.slice/xrdp.service └─3108 /usr/sbin/xrdp
This means that the XRDP on Ubuntu 22.04 is active and running.
Let’s start to configure XRDP.
Configure XRDP on Ubuntu 22.04
From the installation, XRDP added a user named “xrdp”. The xrdp session uses a certificate key file “/etc/ssl/private/ssl-cert-snakeoil.key”.
You need to add the xrdp user to the “ssl-cert” group with the following command:
sudo usermod -a -G ssl-cert xrdp
Now you need to edit the /etc/xrdp/startwm.sh file. Open the XRDP file on Ubuntu 22.04 with your favorite text editor, here we use vi:
sudo vi /etc/xrdp/startwm.sh
Add the following commands before the commands that test & execute Xsession:
Unset DBUS_SESSION_ADDRESS Unset XDG_RUNTIME_DIR
... if test -r /etc/profile; then . /etc/profile fi Unset DBUS_SESSION_ADDRESS Unset XDG_RUNTIME_DIRUnset test -x /etc/X11/Xsession && exec /etc/X11/Xsession exec /bin/sh /etc/X11/Xsession
When you are done, save and close the file.
To apply these changes restart XRDP on Ubuntu 22.04 with the following command:
sudo systemctl restart xrdp
Here you need to adjust the firewall to allow access to port 3389 for remote systems.
To do this you can use the following command:
sudo ufw allow 3389
If you want to open port 3389 for the LAN network, you can use the following command instead:
sudo ufw allow from 192.168.1.0/24 to any port 3389
Now reload the firewall to apply the new rules:
sudo ufw reload
At this point, when you are done with the XRDP configuration on Ubuntu 22.04, you can connect to the remote desktop.
How To Connect To the Remote Desktop
On your Windows client, open the RDP client and enter the IP address of the Ubuntu system.
You can use Winkey+R to open the Run window and type the “mstsc” in it to open the RDP client.
After you click connect, you will receive a warning that the remote system is unknown to your system. click on the “Don’t ask me again for connection to this computer” and press yes to continue.
Then, you will be asked to enter your Ubuntu credentials. Enter the login credentials of the remote Ubuntu 22.04 system to get remote desktop access with Xrdp.
The system will again ask for your system’s password.
Finally, the remote Ubuntu 22.04 LTS graphical screen will be on your Windows system using the Remote desktop protocol.
Here you can manage your remote Ubuntu 22.04 graphically.
At this point, you learn to Install and Configure XRDP on Ubuntu 22.04. Also, you learn to set up an Ubuntu desktop environment.
Hope you enjoy it.