The Source Will Be With You, Always


X11 Forwarding in a FreeBSD Jail


I just spent a few hours trying to get X11 forwarding over SSH working in one of my jails. I was using the same configuration as the host machine, but there's more to it than that. Here's what needs doing:

  1. Install xauth with pkg install xauth

  2. Add the following line to /etc/hosts                          myhostname

    With the IP address and hostname you gave the jail. When you ssh in with X11 forwarding, it will try to resolve the machine's hostname. This tells it to use the IP address of the jail.

  3. Make sure these three lines exist in /etc/ssh/sshd_config

    AllowTcpForwarding yes 
    X11Forwarding yes 
    X11UseLocalhost no

    The last line is important because jails don't get their own network stack, so localhost will point to the actual host and not the jail.

  4. Restart SSH with service sshd_restart

Now everything should be good to go.

published 2015-05-02