Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.

@jklare
Copy link

jklare commented Dec 9, 2020

Thanks!

@git-hub-tig
Copy link

git-hub-tig commented Aug 21, 2021

wonderful! thank you, big brother!

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