-
Install
Xquartzto get X11 support on MacOS. You can googleXquartzand download it from its official site, or install using HomeBrew.brew cask install xquartz
-
Launch
Xquartz. Go toPreference->Security, click the boxAllow connections from clients. NOTE: You have to lauchXquartzwithAllow connections from clientsenable everytime you want tosshto remote server with X11 forwarding support. -
Lauch
terminaloriterm. Add environmentDISPLAY.# 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.
-
Lauch
terminaloriterm, use flag-Yinstead of-Xwithssh.ssh -Y user@address
-
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.
-
Why do I have to add environment
DISPLAY?Please see https://askubuntu.com/a/432257/745885.
-
Why do I have to use
-Yinstead 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: 15This problem is sovled when using
-Yinstead 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.
Thanks a lot. Solved my problem.