SSH X11 Forwarding not working properly

I am trying to display windows from a Linux machine on my MacBook Air (macOS 11.0.1). I ssh into the Linux machine with "ssh -XY username@linuxhost". Ever since Catalina, I have not been able to successfully display windows and get the following error message:


Unable to init server: Could not connect: Connection refused


(eog:14338): Gtk-WARNING **: 10:55:26.520: cannot open display: localhost:11.0


I have tried every single fix I could find online including:


  • Changing the settings in .ssh/config on my MacBook (ForwardX11 yes, ForwardX11Trusted yes, XAuthLocation /opt/local/bin/xauth)
  • Changing those same settings in the system wide file (/usr/local/etc/ssh/ssh_config)
  • Changing some of the settings in the Linux machine sshd_config file
  • Using the command "xhost +" on my MacBook
  • Using -X or -Y flags in my ssh command


Those are the main solutions people offer, but none of them have worked for me. It worked perfectly before upgrading to Catalina, and older MacBooks (macOS 10.12 and below) can still display windows from this Linux machine just fine. This MacBook can display things from other computers just fine too.


I have stumbled upon a very strange behavior. If I ssh into the Linux machine in one terminal, it does not display things. If I open a second terminal and ssh into the Linux machine while keeping the first terminal open and logged in, I can successfully display things. With both terminals open, the first one works properly now. If I close the second terminal, the first one stops working again. But if I close the first terminal, the second one continues to work. I have no idea what that means, but maybe it can help someone else to diagnose the problem.

MacBook Air 13″, macOS 10.15

Posted on Dec 3, 2020 9:18 AM

Reply
1 reply

Dec 28, 2020 5:10 PM in response to bamunson

My problem is somewhat different but maybe related. I have a MacBook Pro 13" (2017) running Catalina. I find that I can ssh -Y user@remote.machine.edu and open X11 window just fine with XQuartz installed on the Mac, but sometimes the forwarded windows get "lost". I don't know what else to call it but the windows are gone. Usually if I go to lunch and come back, the window forwarded from the linux server I'm logged into will be gone. If I swipe up to see all the desktops, I see the windows, but when I click on them they disappear rather than being moved to the foreground. Sometimes I can grab it and move it to the MacBook screen from the external monitor attached to the laptop, but sometimes even that does not work. I also noticed that this issue I think is happening only when I have my external monitor attached to my MacBook. However, when I used to work in my office before last March, I do not recall this happening even when I left for the day and returned to the office, my X11 windows would all be there. So this must have happened after a certain upgrade of Catalina after around Feb 2020.


I run Matlab and I am aware that this software in particular has issues of this sort. But I have noticed it with emacs as well, which also opens an X11 window. This is unique to my ssh sessions to my linux server. Running matlab from my Mac does not result in lost windows, even after an overnight break. It is related to the ssh session I believe.



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

SSH X11 Forwarding not working properly

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.