Skip to content

Instantly share code, notes, and snippets.

@fengyuentau
Last active March 13, 2024 08:15
Show Gist options
  • Star 35 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save fengyuentau/7c43c06fb563752b6947affaf4677f2a to your computer and use it in GitHub Desktop.
Save fengyuentau/7c43c06fb563752b6947affaf4677f2a to your computer and use it in GitHub Desktop.
Enable X11 forward for ssh to load images from remote server on MacOS Mojave

Enable X11 forward to load images from remote server on MacOS Mojave

Steps

  1. Install Xquartz to get X11 support on MacOS. You can google Xquartz and download it from its official site, or install using HomeBrew.

    brew cask install xquartz
  2. Launch Xquartz. Go to Preference -> Security, click the box Allow connections from clients. NOTE: You have to lauch Xquartz with Allow connections from clients enable everytime you want to ssh to remote server with X11 forwarding support.

  3. Lauch terminal or iterm. Add environment DISPLAY.

    # to add an environment entry only working on current terminal, use `export`
    export DISPLAY=:0
    # to add an environment entry working on every terminal,
    # append `export DISPLAY=:0` to `.bashrc` or `.zshrc` in case you use zsh.
  4. Lauch terminal or iterm, use flag -Y instead of -X with ssh.

    ssh -Y user@address

FAQ

  1. Why do I need to install Xquartz?

    From https://stackoverflow.com/a/50182736/6769366,

    XQuartz is standard. It used to come bundled with the OS, but Apple removed it back around Mavericks.

  2. Why do I have to add environment DISPLAY?

    Please see https://askubuntu.com/a/432257/745885.

  3. Why do I have to use -Y instead of -X?

    I got the following error when trying to run a python script which draws some curves using matplotlib:

    X Error of failed request:  BadAccess (attempt to access private resource denied)
    Major opcode of failed request:  18 (X_ChangeProperty)
    Serial number of failed request:  12
    Current serial number in output stream:  15

    This problem is sovled when using -Y instead of -X. Haven't got enough time to find exact explanation, just post a link for those who are curious: Can't run “ssh -X” on MacOS Sierra.

@Ainevsia
Copy link

Ainevsia commented Aug 2, 2019

Thanks a lot. Solved my problem.

@jklare
Copy link

jklare commented Dec 9, 2020

Thanks!

@git-hub-tig
Copy link

wonderful! thank you, big brother!

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