Content
Setting up RDP to connect to Ubuntu/CentOS/Debian
Setting Up Remote Desktop Protocol (RDP) on Ubuntu, CentOS, and Debian
Introduction
Using the Remote Desktop Protocol (RDP), you can access a remote Windows server's graphical user interface from anywhere with a network connection. RDP operates on a client-server model, where the RDP client is installed on the local machine, and the RDP server runs on the remote machine.
This guide will walk you through setting up RDP to connect to Ubuntu, CentOS, or Debian. You will learn how to configure and access a remote Linux server using an RDP connection.
Step-by-Step Guide to Setting Up RDP and Desktop Environment on Ubuntu/CentOS/Debian
This section covers installing and configuring a desktop environment on your server. By default, a standard Ubuntu server comes with a terminal-only interface. To access a graphical user interface, you need to install a desktop environment.
First, connect to your server via SSH and update the package list:
1) Connect to the virtual server via SSH and update the system:
Ubuntu/Debian
sudo apt-get update
CentOS
sudo yum -y update
2) Install the required packages:
Ubuntu/Debian
sudo apt-get install xrdp
CentOS
sudo yum install -y epel-release sudo yum install -y xrdp
3) Enable and start the xRDP service:
sudo systemctl enable xrdp sudo systemctl start xrdp
4) Open the RDP port for remote connections:
Ubuntu/Debian
sudo ufw allow 3389/tcp
CentOS
If using FirewallD, open port 3389/TCP for RDP:
sudo firewall-cmd --add-port=3389/tcp --permanent sudo firewall-cmd --reload
5) Restart the xRDP server to apply changes:
sudo /etc/init.d/xrdp restart
Connecting to the Desktop
To connect, open the Windows Remote Desktop Connection application. Enter the server's IP address and username, then click Connect.

Upon connection, you may see a security warning due to connecting to a Linux-based system. Click "Yes" to proceed.
In the login window, select Xorg as the session, enter the user's password, and click OK.

Note: If you receive a message stating that Remote Desktop cannot connect, verify that the Remote Desktop option is enabled in the system settings.
After logging in, you will gain access to the Ubuntu/CentOS/Debian desktop environment.
Verifying the RDP Connection
To test the connection using the Windows Remote Desktop Connection client, follow these steps:
- Launch the Remote Desktop Connection application by searching for it in the Start menu or typing
mstsc
in the Run dialog (Windows + R) and pressing Enter. - In the Remote Desktop Connection window, enter the public IP address of the remote server in the Computer field.
- Enter the username associated with your remote server in the Username field.
- To save these settings for future use, click Save As and specify a file name for the connection.
- Click Connect to initiate the connection.
Installing a Desktop Environment
Why is a Desktop Environment Necessary?
RDP requires a graphical desktop environment to display the interface. Server versions of Linux, such as Ubuntu Server or CentOS Minimal, typically come without a graphical interface, offering only a terminal. Without a desktop environment like Xfce, GNOME, or KDE, xRDP will fail to display a desktop, potentially resulting in errors like a black screen.
Installing a Desktop Environment
We recommend using a lightweight desktop environment like Xfce, which is resource-efficient for servers. Use the following commands to install it:
Distribution | Xfce Installation Command |
---|---|
Ubuntu/Debian |
sudo apt-get install xfce4 xfce4-goodies |
CentOS/Rocky Linux/AlmaLinux |
sudo dnf install -y epel-release && sudo dnf groupinstall -y "Xfce" |
After installing Xfce, ensure a display manager like lightdm
or gdm
is installed and configured. The display manager handles graphical logins. It is usually installed automatically with Xfce, but you can verify its presence with:
sudo systemctl status lightdm # or sudo systemctl status gdm
If a display manager is not installed, install one:
- For Ubuntu/Debian:
sudo apt-get install lightdm
- For CentOS/Rocky Linux/AlmaLinux:
sudo dnf install gdm
(orsudo dnf install lightdm
for Xfce)
Restart the server or xRDP service after installation:
sudo systemctl restart xrdp
Choosing a Session
When connecting via an RDP client (e.g., Microsoft Remote Desktop), select the "Xorg" session in the login menu. Choosing an incorrect session may cause display issues.
Enhancing Security
Why is Security Important?
RDP, especially when port 3389 is publicly accessible, is a common target for attackers. Without proper security measures, such as protection against RDP against brute-force attacks or encryption, RDP connections are vulnerable to unauthorized access, data leaks, or man-in-the-middle attacks. Here are some security recommendations:
Security Recommendations
- Strong Passwords Use complex passwords for all accounts used for RDP access.
- Restrict Access by IP
Configure the firewall to allow RDP connections only from specific IP addresses to reduce the risk of brute-force attacks. Example commands:
Distribution Commands to Restrict Access Ubuntu/Debian sudo ufw allow from <IP_ADDRESS> to any port 3389
CentOS/Rocky Linux/AlmaLinux sudo firewall-cmd --add-port=3389/tcp --permanent sudo firewall-cmd --add-source=<IP_ADDRESS> --permanent sudo firewall-cmd --reload
Replace
<IP_ADDRESS>
with your client's IP address. - Regular Updates
Regularly update the system and xRDP package to patch known vulnerabilities:
- For Ubuntu/Debian:
sudo apt-get update && sudo apt-get upgrade
- For CentOS/Rocky Linux/AlmaLinux:
sudo dnf update
- For Ubuntu/Debian:
- Use a VPN or Bastion Host For added security, configure RDP access through a VPN (e.g., Tailscale or OpenVPN) to hide port 3389 from the public internet. Alternatively, use a bastion host for secure connections.
- Disable RDP When Not in Use
If RDP is not needed continuously, disable the xRDP service:
sudo systemctl stop xrdp
Re-enable it when needed:sudo systemctl start xrdp
- Encrypt Connections
Ensure xRDP is configured to use encryption. By default, xRDP supports 128-bit encryption. Verify the settings in
/etc/xrdp/xrdp.ini
, ensuring thesecurity_layer
is set tordp
ortls
.
Troubleshooting Common Issues
Common Problems
Even with proper setup, issues with xRDP may arise. Here are the most common problems and their solutions:
- Connection Errors
If you see "Remote Desktop can't connect to the remote computer," check the following:
- Ensure the xRDP service is running:
sudo systemctl status xrdp
. If inactive, start it:sudo systemctl start xrdp
. - Verify that port 3389 is open in the firewall:
- For Ubuntu/Debian:
sudo ufw status
- For CentOS/Rocky Linux/AlmaLinux:
sudo firewall-cmd --list-ports
If closed, open it:- For Ubuntu/Debian:
sudo ufw allow 3389/tcp
- For CentOS/Rocky Linux/AlmaLinux:
sudo firewall-cmd --add-port=3389/tcp --permanent && sudo firewall-cmd --reload
- For Ubuntu/Debian:
- For Ubuntu/Debian:
- Ensure the xRDP service is running:
- Black or Blank Screen
A black screen after login may be caused by:
- Missing desktop environment. Ensure Xfce or another environment is installed.
- Incorrect session selection. Choose "Xorg" in the RDP client's login menu.
- xRDP configuration issues. Edit
/etc/xrdp/xrdp.ini
and setmax_bpp=24
:sudo nano /etc/xrdp/xrdp.ini
Find the[xrdp1]
section and add or modify:max_bpp=24
Restart xRDP:sudo systemctl restart xrdp
- Authentication Issues
If login fails, check:
- Correct username and password.
- Graphical login permissions for the user. Ensure the account is not restricted to terminal-only access.
- Settings in
/etc/xrdp/xrdp.ini
. Ensureaddress
is set to0.0.0.0
:address=0.0.0.0
- Distribution-Specific Issues
Some versions, like Ubuntu 18.04.2, have known xRDP issues, such as green or black screens. In such cases:
- Ensure the latest xRDP version is installed:
- For Ubuntu/Debian:
sudo apt-get install xrdp
- For CentOS/Rocky Linux/AlmaLinux:
sudo dnf install xrdp
- For Ubuntu/Debian:
- Try an alternative desktop environment, such as GNOME, if Xfce does not work.
- Ensure the latest xRDP version is installed:
- Low Performance or Lag
If the RDP connection is slow, check:
- Network connection speed.
- xRDP graphics settings. Reducing color depth (e.g., to 16-bit) in
/etc/xrdp/xrdp.ini
may improve performance but reduce image quality.
Configuring Audio in xRDP
Forwarding audio through xRDP can be challenging and depends on the distribution. Below are recommended methods for Ubuntu Server 22.04, 24.04, and Debian 11, 12.
Ubuntu Server 22.04, 24.04, and Debian 11, 12 (Recommended for RDP with Audio)
The easiest and most reliable method is to use Ubuntu Server 22.04, 24.04, or Debian 11, 12 and install xRDP with audio support using the xrdp-installer
script.
Step-by-Step Instructions:
- Update the system:
sudo apt update -y && sudo apt upgrade -y sudo reboot
- Install a desktop environment:
- For Ubuntu Server 22.04, 24.04:
sudo apt install ubuntu-desktop # GNOME sudo apt install xubuntu-desktop # Xfce sudo apt install kubuntu-desktop # KDE sudo reboot
- For Debian 11, 12:
sudo apt install gnome # GNOME sudo apt install xfce4 # Xfce sudo apt install plasma-desktop # KDE sudo reboot
- For Ubuntu Server 22.04, 24.04:
- Download and extract the script:
wget https://www.c-nergy.be/downloads/xRDP/xrdp-installer-1.5.3.zip unzip xrdp-installer-1.5.3.zip
- Make the script executable:
chmod +x xrdp-installer-1.5.3.sh
- Run the script as a non-root user:
./xrdp-installer-1.5.3.sh -s
- Reboot the server:
sudo reboot
After rebooting, connect via an RDP client (e.g., Microsoft Remote Desktop). Audio should work automatically if enabled in the client.
Alternative: Manual Setup for Ubuntu/Debian
If you prefer not to use the xrdp-installer
script, you can configure audio manually:
- Install PulseAudio and the redirection module:
sudo apt-get install pulseaudio pulseaudio-module-xrdp
- Enable PulseAudio for the user:
systemctl --user enable pulseaudio systemctl --user start pulseaudio
- Restart xRDP:
sudo systemctl restart xrdp
⚠️ Note: In some Ubuntu versions, the
pulseaudio-module-xrdp
package may not be available in standard repositories. Using the script is recommended.
RHEL-Based Systems: Rocky Linux, AlmaLinux, CentOS 8+, Fedora
Audio support on RHEL-based systems requires manual compilation of the pulseaudio-module-xrdp
module, which is complex and may not always be stable.
Basic Steps (Overview):
- Install development tools:
sudo dnf groupinstall "Development Tools" sudo dnf install rpmdevtools dnf-utils pulseaudio-libs-devel
- Enable PowerTools (for AlmaLinux/Rocky):
sudo dnf config-manager --set-enabled powertools
- Download and build PulseAudio sources.
- Clone and build the
pulseaudio-module-xrdp
repository:git clone https://github.com/neutrinolabs/pulseaudio-module-xrdp.git cd pulseaudio-module-xrdp ./bootstrap ./configure make sudo make install
- Reboot the system:
sudo reboot
⚠️ This process is not recommended for inexperienced users. Consider using RDP without audio or connecting via SSH/VNC instead.
Troubleshooting Audio Issues
- Verify audio is enabled in the RDP client (e.g., in Microsoft Remote Desktop, check the "Local Resources" tab).
- Check PulseAudio status:
systemctl --user status pulseaudio
- Verify xrdp-sink and xrdp-source devices:
- Install and open
pavucontrol
(if available). - Ensure audio is not muted and the output is configured correctly.
- Install and open
- Check
/etc/pulse/daemon.conf
settings:default-sample-rate = 44100
After changes:systemctl --user restart pulseaudio
- Verify user permissions:
Ensure the user is in the
audio
group and has access to audio devices.