I haven't tested this, but as far as I know, it should be possible to shutdown the local X11 server (usually by stopping the X11 Display Manager, whether it's
sddm, the classic
xdm or any other
*dm), and then logging in on a virtual console and starting a custom X11 session, like this for GNOME:
xinit ssh -X user@remote-server gnome-session
Or like this for KDE:
xinit ssh -X user@remote-server startkde
Normally, the X11 Display Manager will start the X11 server, present the login dialog and process the authentication (optionally running some initialization scripts as root before and/or after the authentication), then run a single command or script as the logging-in user that will act as the backbone of the session. The classic default version of that script might be found as
/etc/X11/Xsession, but desktop environments like Gnome and KDE may replace that with their own commands. This command/script will stay alive through the lifetime of the session: if it dies for any reason, the X11 Display Manager will assume the session was logged out or crashed, and will reset the X11 server and start over.
When you use
startx to start a single X11 session from a virtual console without a X11 Display Manager, it is a wrapper script that uses
xinit to start the X11 server and the session command/script.
What you want to do, is to start the X11 server, but use
ssh -X in lieu of the local session command, to run the actual X11 session command/script in the remote host.
xinit command will start the local X11 server, but its only client will be the
ssh command. That
ssh will establish X11 forwarding, connect to the remote host, log in, and run whatever command is needed to start the appropriate desktop environment session at the remote host. Since the
$DISPLAY variable and the
~/.Xauthority file will be set by
ssh -X, so any X11 application, including a X11 window manager, should be able to run.
However, as the X11 server will not be accessible locally, various performance-improving X11 protocol extensions will automatically be unavailable, and the network connection + SSH encryption will cause some noticeable latency. Any interaction between the window manager and any other X11 application must go through the X11 server, which means two trips through the network each way. So it will definitely be more sluggish than running a local desktop.
Some desktop widgets may also be confused, as you won't necessarily have all the expected levels of access to the hardware devices and/or the system D-Bus of the host when running remotely.