Skip to content

Instantly share code, notes, and snippets.

@anselanza
Last active November 7, 2024 22:33
Show Gist options
  • Save anselanza/d75432bf481be90ebb357489a1c5e006 to your computer and use it in GitHub Desktop.
Save anselanza/d75432bf481be90ebb357489a1c5e006 to your computer and use it in GitHub Desktop.
Viewing graphical output on from a remote Linux host, on your Mac

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

1. Install X11 server

You will need XQuartz, since X11 server is not installed with MacOS after version 10.7

Download here: https://www.xquartz.org/

2. Enable forwarding on server

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

3. Enable forwarding on client

On the client (your Mac) side, edit ~/.ssh/config to include:

Host *
  ForwardAgent yes
  ForwardX11 yes

4. SSH with forwarding enabled

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

5. Do something graphical

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.

@mircealungu
Copy link

Note that on my Mac OS Sonoma, I had to reboot before step 4; otherwise the $DISPLAY would not be defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment