Ubuntu Server 22.04配置lightdm+GNOME后RDP仅在主机接显示器时可用的问题咨询
Hey Edward, let's unpack this frustration you're feeling—totally get why having to plug a monitor into a headless server defeats the purpose of remote access. Let's break down what's happening and fix it:
First, to answer your core question: Unlike Windows Server's RDP which spawns fully independent sessions, your current setup is remote-controlling the physical console session of the Ubuntu machine. Linux desktop environments (like GNOME paired with lightdm) default to checking for a physical display output to initialize a proper session. No monitor? It skips or half-loads the session, making RDP fail.
Here are the most reliable fixes to make RDP work headless:
1. Force lightdm to start a virtual session without a physical monitor
Edit the lightdm config file to override its display detection:
sudo nano /etc/lightdm/lightdm.conf
Find the [Seat:*] section (add it if it doesn't exist) and add these lines:
[Seat:*] xserver-command=X -core -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch -sharevts xserver-display-number=0 allow-empty-password=false # Keep this true only if you're okay with no-password logins
Save and exit, then restart lightdm:
sudo systemctl restart lightdm
2. Configure xrdp to create independent GNOME sessions
If you're using xrdp (the most common RDP server for Ubuntu), you can set it up to spawn separate sessions just like Windows does:
- Install required packages if you haven't already:
sudo apt install xrdp xorgxrdp gnome-session - Edit the xrdp config to use GNOME as the default session:
In thesudo nano /etc/xrdp/xrdp.ini[Globals]section, set:
Then find theSecurityLayer=tls # More secure than the default[Xorg]section and ensure it looks like this:[Xorg] username=ask password=ask ip=127.0.0.1 port=-1 - Create a custom GNOME session file for xrdp:
Paste this content:sudo nano /usr/share/xsessions/gnome-xrdp.desktop[Desktop Entry] Name=GNOME on Xrdp Comment=GNOME desktop for independent RDP sessions Exec=gnome-session Type=Application - Restart xrdp to apply changes:
sudo systemctl restart xrdp
Now every RDP connection will get its own fresh GNOME session, no physical monitor required.
3. Use a dummy virtual display driver
If the above methods don't stick, you can force Xorg to create a virtual display regardless of hardware:
- Install the dummy driver:
sudo apt install xserver-xorg-video-dummy - Create a custom Xorg config file:
Paste this (adjust the resolution to your preference):sudo nano /etc/X11/xorg.conf.d/20-dummy.confSection "Device" Identifier "DummyDevice" Driver "dummy" VideoRam 256000 EndSection Section "Monitor" Identifier "DummyMonitor" HorizSync 5.0 - 1000.0 VertRefresh 5.0 - 200.0 Modeline "1920x1080" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync EndSection Section "Screen" Identifier "DummyScreen" Device "DummyDevice" Monitor "DummyMonitor" DefaultDepth 24 SubSection "Display" Depth 24 Modes "1920x1080" EndSubSection EndSection - Restart lightdm or xrdp, and your server will now "think" it has a physical monitor connected.
To wrap up: Linux's desktop stack was originally built around physical console access, so it doesn't automatically do the headless session magic Windows does. But with these tweaks, you can get fully independent, headless RDP sessions just like you expect.
备注:内容来源于stack exchange,提问作者Edward A. Ludwig

