DEV Community

Big Mazzy
Big Mazzy

Posted on

Fix xrdp Black Screen on Ubuntu 24.04: Session Startup

TL;DR: Install XFCE, set ~/.xsession to start it, then terminate only the affected xrdp session and reconnect.

The problem

After an RDP login to Ubuntu 24.04, the connection succeeds but the screen stays black instead of showing a desktop. Authentication has worked; the black screen does not mean that the user has been logged out. The useful next step is to trace what the session tries to start, rather than repeatedly reconnecting and hoping the desktop appears.

This walkthrough checks the user's session startup file over SSH, replaces its faulty startup instruction with XFCE's startup command, and reconnects after restarting only the relevant xrdp session. It keeps the scope narrow: do not terminate unrelated sessions on a shared or production server.

Why it happens

An RDP login can authenticate successfully and still fail to present a usable desktop if the session startup file launches the wrong process. In this case, ~/.xsession contains exec sleep infinity. That process stays alive, but it does not start a graphical desktop, so the RDP window remains black.

The fix has two parts. First, install XFCE so there is a desktop environment available. Then make the user's session file launch XFCE with startxfce4. Finally, identify the xrdp session and terminate that session so the next connection starts with the corrected configuration. This is a session-startup issue, not a password problem.

Step-by-step fix

  1. Connect to the Ubuntu machine through SSH as the affected user and inspect the session file. The command reads the current contents; it does not change them.
   cat ~/.xsession
Enter fullscreen mode Exit fullscreen mode

In this example, the file contains:

   exec sleep infinity
Enter fullscreen mode Exit fullscreen mode

The output should match the file contents. If it shows exec sleep infinity, the session is not being told to launch a desktop.

  1. Install XFCE. This provides the desktop environment that the RDP session will start. Allow the installation to finish before continuing.
   sudo apt install -y xfce4
Enter fullscreen mode Exit fullscreen mode
  1. Replace the user's session startup file with the XFCE startup command. The command writes startxfce4 into ~/.xsession.
   printf 'startxfce4\n' | tee ~/.xsession
Enter fullscreen mode Exit fullscreen mode

The resulting file contents should be:

   startxfce4
Enter fullscreen mode Exit fullscreen mode
  1. List the user's login sessions so you can identify the xrdp session. In the sample output, 7 is the session number and ubuntu is the user. Session numbers are examples and placeholders: use the number shown for your own xrdp session, not necessarily 7.
   loginctl list-sessions --no-legend | awk '{print $1, $3}'
Enter fullscreen mode Exit fullscreen mode

Example output:

   7 ubuntu
Enter fullscreen mode Exit fullscreen mode
  1. Check that the session you identified belongs to xrdp. The 7 below is the sample session number; substitute the session number from your own session list.
   loginctl show-session 7 -p Service
Enter fullscreen mode Exit fullscreen mode

Example output:

   Service=xrdp-sesman
Enter fullscreen mode Exit fullscreen mode

Confirm that the service is xrdp-sesman before terminating anything. This check helps avoid disrupting a different login session.

  1. Terminate only the verified xrdp session. Replace 7 with the session number you checked above. This disconnects that session so the next RDP connection can start using the corrected session file.
   sudo loginctl terminate-session 7
Enter fullscreen mode Exit fullscreen mode

Reconnect through RDP after the session has been terminated. The new session should launch the XFCE desktop.

How to verify

Reconnect to the server through RDP and check that the XFCE desktop appears instead of a black screen. Open the Applications menu to confirm that the desktop is responsive, not merely displaying a background. Then disconnect and reconnect once more. Seeing the desktop again after a second connection is a useful confirmation that session startup is now consistent.

If the screen is still black, return to the specific checks above: confirm the session file contains startxfce4, and make sure you identified and terminated the xrdp session rather than another session. Treat the sample session number as a placeholder; session IDs can differ between systems and change over time.

Common mistakes

  • Terminating a session based only on its number without checking its service can interrupt the wrong user session. Verify that the selected session reports Service=xrdp-sesman.
  • Assuming authentication failure is the cause can send troubleshooting in the wrong direction. In this scenario, login succeeds; the problem is that the session does not launch a desktop.
  • Leaving exec sleep infinity in the session file will keep reproducing the black screen. The file needs to contain the XFCE startup line instead.
  • Reconnecting without ending the affected xrdp session may leave you looking at the existing broken session. Terminate only the verified xrdp session, then reconnect.
  • If you want a clean Ubuntu box to practice on, PowerVPS is a reasonable choice: https://powervps.net/?from=32

Watch more fixes on Server Lab: https://www.youtube.com/channel/UCov7rfWAnS4c2wF5E9V1Yag

Top comments (0)