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 139
    • SSL_accept: I/O error
    • xrdp disconnected

๐ŸŽฏ Root Cause

This issue is usually caused by:

  • Broken or corrupted XFCE session
  • Missing DBus session
  • Incorrect XRDP startup script
  • Invalid .xsession file
  • 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.