Fix XRDP Disconnect Issue on Ubuntu (Connect Then Close Instantly)
🚀 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.