How to Set Up a Remote Desktop with xrdp

Setting up a remote desktop connection using xrdp allows you to access and control a Linux machine remotely. xrdp is an open-source implementation of the Microsoft Remote Desktop Protocol (RDP), making it compatible with most remote desktop clients. This guide will walk you through the steps to install and configure xrdp for a seamless remote desktop experience.
1. Prerequisites
Hardware Requirements
- A server or desktop running a Linux distribution (e.g., Ubuntu, Debian, CentOS).
- A client machine with an RDP client (e.g., Microsoft Remote Desktop).
Software Requirements
- sudo or root access to the Linux machine.
- An active network connection between the client and server.
2. Installing xrdp
Step 1: Update the System
Before installing xrdp, update your package list to ensure all packages are up-to-date:
sudo apt update
sudo apt upgrade -y
Step 2: Install xrdp
Install xrdp from your Linux distribution’s package manager:
Ubuntu/Debian:
sudo apt install xrdp -y
CentOS/RHEL:
Enable the EPEL repository and install xrdp:
sudo yum install epel-release -y
sudo yum install xrdp -y
Step 3: Start and Enable the xrdp Service
Start the xrdp service and ensure it runs on boot:
sudo systemctl start xrdp
sudo systemctl enable xrdp
Step 4: Verify the Installation
Check the status of the xrdp service:
sudo systemctl status xrdp
You should see a message indicating that the service is active and running.
3. Configure xrdp
Step 1: Allow RDP Connections in the Firewall
Open the RDP port (3389) in your firewall to allow remote connections:
UFW (Ubuntu/Debian):
sudo ufw allow 3389/tcp
sudo ufw reload
firewalld (CentOS/RHEL):
sudo firewall-cmd --permanent --add-port=3389/tcp
sudo firewall-cmd --reload
Step 2: Configure Desktop Environment
By default, xrdp uses the Xfce desktop environment. If Xfce is not installed, install it:
Ubuntu/Debian:
sudo apt install xfce4 -y
CentOS/RHEL:
sudo yum groupinstall "Xfce" -y
Set Xfce as the default session for xrdp by creating or editing the ~/.xsession
file:
echo xfce4-session > ~/.xsession
Restart the xrdp service:
sudo systemctl restart xrdp
Step 3: Modify xrdp.ini (Optional)
To customize the xrdp settings, edit the configuration file:
sudo nano /etc/xrdp/xrdp.ini
You can modify settings like port number, session limits, or security options.
Restart xrdp to apply changes:
sudo systemctl restart xrdp
4. Connect to the Remote Desktop
Step 1: Get the Server’s IP Address
Find the IP address of the server using:
ip addr
Step 2: Use an RDP Client
- Open your RDP client (e.g., Microsoft Remote Desktop on Windows or Remmina on Linux).
- Enter the server’s IP address and port (default: 3389).
- Provide your Linux username and password when prompted.
5. Troubleshooting
Issue 1: Black Screen or Connection Issues
- Ensure the desktop environment is correctly installed and set in
~/.xsession
. - Check the xrdp logs:
sudo tail -f /var/log/xrdp-sesman.log sudo tail -f /var/log/xrdp.log
Issue 2: Firewall Blocking the Connection
- Double-check that port 3389 is open and accessible.
- Test connectivity with:
telnet <server-ip> 3389
Issue 3: Authentication Problems
- Verify the username and password.
- Ensure the user has permission to log in remotely.
6. Best Practices
- Use a Secure Connection: Consider using SSH tunneling or VPN to secure your RDP connection.
- Restrict Access: Limit access to the RDP port to specific IP addresses.
- Keep Software Updated: Regularly update xrdp and your system packages.
7. Conclusion
Setting up xrdp enables you to remotely access your Linux machine using a familiar RDP client. With its straightforward installation and configuration, xrdp is an excellent choice for managing remote systems efficiently. Follow this guide to create a reliable and secure remote desktop setup tailored to your needs.