This is not for full desktop screen sharing. It allows you to forward the graphical contents of individual windows to your Mac from a remote Linux machine, regardless of whether that machine is connected to a physical display or not.
Steps below based very much on https://unix.stackexchange.com/a/46748
You will need XQuartz, since X11 server is not installed with MacOS after version 10.7
Download here: https://www.xquartz.org/
On the server (remote Linux host) side, edit /etc/ssh/sshd_config
to include:
X11Forwarding yes
X11DisplayOffset 10
Make sure xauth
is installed, e.g. which xauth
On the client (your Mac) side, edit ~/.ssh/config
to include:
Host *
ForwardAgent yes
ForwardX11 yes
The critical part is the -X
flag. For example:
ssh -X -v [email protected]
The -v
(verbose) is helpful for troubleshooting
On the remote (server) side, the $DISPLAY variable should now be set if all has gone well. For example:
$ echo $DISPLAY
localhost:10.0
Assuming everything is set up correctly and "works", nothing different will happen initially. (You'll see a remote terminal as normal.)
However, when you launch an application that targets the display (e.g. OpenGL imshow), then XQuartz will open one or more windows on your Mac with the graphical output.
Close the window when you want the application to continue (or complete/quit, depending on the intended functionality). If you want to keep the session alive, do not quit XQuartz application itself - just close any windows that were opened.
Note that on my Mac OS Sonoma, I had to reboot before step 4; otherwise the $DISPLAY would not be defined