Can’t run “ssh -X” on MacOS Sierra

I didn’t need to reinstall XQuartz, but, based on Matt Widjaja’s answer, I came up with a refinement.

  • sudo vi /etc/ssh/ssh_config (This is ssh client config, not sshd_config)
    • Under the Host * entry add (or add where appropriate per-host)
      • XAuthLocation /usr/X11/bin/xauth (The location of xauth changed in Sierra)
      • ServerAliveInterval 60 (Pings the server every 60 seconds to keep your ssh connection alive)
      • ForwardX11Timeout 596h (Allows untrusted X11 connections beyond the 20 minute default)

No need to restart ssh, except, of course, existing ssh client connections.

It sounds like -Y (trusted X11) would be preferable to untrusted. If you switch over to trusted, the ForwardX11Timeout line can probably be removed.

The ServerAliveInterval line is also an optional preference.

It may also be possible to make these changes in ~/.ssh/config (the user’s config file) but the permissions have to be correct.

EDIT: I removed ForwardX11 and ForwardX11Trusted. They aren’t needed and ForwardX11 is less secure and causes problems for git (or other tools using ssh).

Leave a Comment