Yes, you can but it's not like sharing an X server, but redirecting the X protocol's input (keyboard and mouse) and output (Window drawing) between an application executing at a remote computer, and the X server of the computer you're sitting at.
TL;DR: You need to SSH to the second computer establishing an X tunnel.
For example, you're sitting in PI1, and you want to run some apps at PI2, but seeing their graphical output in your local computer, PI1. I will use scratch as an example.
Imagine that your PI2 is at 192.168.0.11.
You'd do this:
Bash:
pi@pi1:~ $ ssh -XY [email protected]
[email protected]'s password: *******
Linux raspberrypi 5.4.72-v7l+ #1356 SMP Thu Oct 22 13:57:51 BST 2020 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Dec 9 13:56:10 2020 from 192.168.0.132
Wi-Fi is currently blocked by rfkill.
Use raspi-config to set the country before use.
pi@pi2:~ $ scratch
Then you would see the scratch window in PI1, while it's running on PI2.
if it fails, try the following command first:
Bash:
pi@pi1:~ $ xhost +
access control disabled, clients can connect from any host
What did we do here?
xhost +
enables applications in other hosts (in any host) to connect to our local X server to display graphics on, and to accept input from. That enables our computer as an X terminal for other hosts' applications.
ssh -XY user@computer
establishes a SSH session which will tunnel the X protocol to our local server.
You can do this with as many Raspberry Pi (or servers) you'd have into your local network, distributing your workload across the network as needed.
It will normally work without the
xhost +
before, if the default configuration of your computers is friendly enough. I just tried, and I can do X forwarding from my Raspberry Pi, that usually runs pihole but has a full Raspbian, to my laptop running Manjaro, without running the
xhost +
before.
You can do the above even if someone else is using the other Raspberry Pi (or computer) interactively, as Linux is multi-user. Back in the days at the uni the labs were easily overcrowded, so I usually did this to use a lab's linux computer, from the library, at the same time someone else was working on it. As long as your fellow student didn't reboot the computer, those machines could easily handle a student on-site, and at least other two remotely to do things like network programming and Octave simulations (and they were 16 MB Pentium II, in 1998-2000).