I am trying to run a program after enabling X windows port forwarding.

My sshd_config file in /etc/ssh/sshd_config is configured such that:

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes

and my ssh_config file in /etc/ssh/ssh_config has:

Host *
ForwardAgent yes
ForwardX11 yes

I try to enable X Windows port forwarding with

lemon:~ # ssh -X localhost
lemon:~ # echo $DISPLAY

lemon:~ # /usr/bin/SMclient
xdpyinfo:  unable to open display "".
Unable to launch GUI due to X server display setting problem, Exiting .

So $DISPLAY is set to nothing. I have tried everything I've seen online. Originally there was no .Xauthority file so I copied from /var/run/gdm/auth-for--/database and renamed the file .Xauthority

I then tried

lemon:~ # xauth generate :0 . trusted
Invalid MIT-MAGIC-COOKIE-1 keyxauth: (argv):1:  unable to open display ":0".

When this didn't work, I deleted the old .Xauthority file and then:

lemon:~ # touch ~/.Xauthority
lemon:~ # xauth generate :0 . trusted
No protocol specified
xauth: (argv):1:  unable to open display ":0".  

And many others suggested to run host + which just leads to

lemon:~ # xhost +
xhost:  unable to open display ""
  • Fiddling with .Xauthority and xhost is pointless because that's not where you have a problem (but be careful, your fiddling may have caused another problem, depending on what you've ended up with in .Xauthority). These are about authorizing the connection to the display, but you don't have a display to connect to. You need to figure out why DISPLAY is not set. Do you have anything that changes DISPLAY in your startup file (/etc/profile, ~/.bashrc, ~/.profile, ~/.bash_profile, …)? If so remove it. Aug 8, 2017 at 22:50
  • Can you still run X programs without going through SSH? (Your fiddling may have broken that. If so I suggest you log out and back in.) What does echo $DISPLAY; ssh -X localhost 'echo $DISPLAY' show? Aug 8, 2017 at 22:52
  • What distro are you using?
    – Jakuje
    Aug 9, 2017 at 11:07
  • Did you try `export DISPLAY=:0.0" ?
    – Noam Manos
    Jan 17, 2020 at 11:12
  • @Gilles'SO-stopbeingevil', I have a similar question for which I can't find an answer. You seem to know this subject well, is there any chance you wouldn't mind taking a look at it? unix.stackexchange.com/questions/630428/… (My apologies for my bad manners in asking this in this way. I don't usually do this but I am a bit desperate.)
    – Kvothe
    Jan 22, 2021 at 18:25

1 Answer 1


Along with all the above on macOS13 Ventura you must: In System Settings, General, Allow in Background, XQuartz must be turned on.

  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 11 at 22:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .