How to get X11 windows to open when logged in remotely - e.g. how to get a web browser window on a remote server, when logged in via SSH.

Forwarding on MacOS with Vagrant

Note: Not sure how much of this is required, but after much hacking and frustration, I eventually managed to get it working using this method.

  1. Install XQuartz and run it.

  2. On the remote machine, edit /etc/ssh/sshd_config and set the properties:
    • X11Forwarding yes
    • X11DisplayOffset 10
    • X11UseLocalhost no
  3. On the remote machine, install X11 tools: yum install xorg-x11-xauth

  4. Restart sshd if necessary on the remote host.

  5. On the local machine, edit ~/.ssh/config to set:

    Host *
        XAuthLocation /opt/X11/bin/xauth
        ForwardX11 yes
        ForwardX11Trusted yes
    
  6. vagrant ssh -- -X

NB: If X11 forwarding is required for a user other than vagrant, then copy the file ~vagrant/.Xauthority into to the other user’s home directory:

sudo cp ~vagrant/.Xauthority ~jboss/
sudo chown jboss:jboss ~jboss/.Xauthority
sudo su - myuser
export DISPLAY=127.0.0.1:10.0