๐ Fix XRDP Disconnect Issue on Ubuntu (Connect Then Close Instantly)
If your XRDP connects successfully but disconnects immediately after login, youโre not alone. This is a common issue on Ubuntu servers using XFCE or other desktop environments.
In this guide, weโll fix it step-by-step with a stable, production-ready solution.
โ Problem Symptoms
- RDP connects successfully
- Screen flashes or loads briefly
- Session disconnects instantly
- Logs show errors like:
window manager exited with code 139SSL_accept: I/O errorxrdp disconnected
๐ฏ Root Cause
This issue is usually caused by:
- Broken or corrupted XFCE session
- Missing DBus session
- Incorrect XRDP startup script
- Invalid
.xsessionfile - Stale XRDP processes or PID files
โ Working Solution (Step-by-Step)
๐ง Step 1: Clean XRDP Runtime
sudo pkill -9 xrdp xrdp-sesman
sudo rm -rf /var/run/xrdp
sudo install -d -o xrdp -g xrdp /var/run/xrdp
๐ง Step 2: Fix XRDP Startup Script
Edit the XRDP start script:
sudo nano /etc/xrdp/startwm.sh
Replace entire file with:
#!/bin/sh
export DESKTOP_SESSION=xfce
export XDG_SESSION_DESKTOP=xfce
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR
exec dbus-launch --exit-with-session startxfce4
๐ง Step 3: Reset User Session
rm -f ~/.xsession ~/.Xsession
echo "exec dbus-launch --exit-with-session startxfce4" > ~/.xsession
chmod +x ~/.xsession
๐ง Step 4: Reset XFCE Configuration
mv ~/.config/xfce4 ~/.config/xfce4.bak
๐ง Step 5: Reinstall Required Packages
sudo apt install --reinstall xfce4 xfce4-session xfce4-terminal xorgxrdp dbus-x11 -y
๐ง Step 6: Fix Permissions
chmod 755 ~
๐ง Step 7: Restart XRDP
sudo systemctl daemon-reexec
sudo systemctl restart xrdp
โ Verify XRDP is Running
ss -tulpn | grep 3389
You should see XRDP listening on port 3389.
๐ Optional: Secure Your Server
XRDP port is often targeted by bots. Restrict access:
sudo ufw allow from YOUR_IP to any port 3389
sudo ufw enable
โ ๏ธ Note About SSL Errors
Errors like:
SSL_accept: I/O error
are usually caused by internet bots scanning your server and can be ignored.
๐ง Final Result
- โ XRDP connects successfully
- โ Desktop loads properly
- โ No sudden disconnections
๐ Alternative (More Stable Option)
- NoMachine (high performance, production-grade)
- X2Go (lightweight and SSH-based)
๐ Conclusion
This issue is not caused by XRDP aloneโitโs a combination of session misconfiguration and missing DBus environment. Once corrected, XRDP becomes stable and reliable.
Save this guideโyouโll likely need it again.