Not exactly FreeBSD to FreeBSD, but this is the forum post that came up during my research of Linux -> FreeBSD, so leaving what I found here for posterity.
To enable Linux (from where you ssh, and where you want the X windows to appear, aka X11 server) to FreeBSD (to where you ssh into and run X programs, aka X11 client) X Forwarding, there was some surprising turn needed that was not mentioned in other forums/sources in one place. So:
-
pkg install xauth (if was not yet present)
- You need to
edit the /etc/ssh/sshd_config, and enable the X11Forwarding (either globally or for the given user using the Match User section, at the end there is an example).
service sshd reload. So far standard.
- Do
_not_ change X11UseLocalhost to 'no'. The standard 'yes' is good there (means that the ssh forwarding will bind to localhost, and not to wildcard. Which is good, the x-client apps will try to connect via localhost, as instructed by the properly set DISPLAY variable)
At this point,
if you have an old-ish Linux, things should work (but read below). As a checkpoint, after ssh -X-ing to your FreeBSD host, you should verify:
- `env` prints DISPLAY=localhost:10.0 or similar (11.0 etc)
- `netstat -an` prints an ipv4 listener on 127.0.0.1:6010 (or 6011 etc)
If you try xclock, and it works, all good. If you get a cryptic message `connect /tmp/.X11-unix/X0: No such file or directory`, as it turns out, this is not originating from the host-ran x-client program, but rather from ssh itself as a debug info (if you started ssh with -vv, you would also get messages indicating that ssh detected the attempt that FreeBSD client wants to connect through the forwarded port).
So, that cryptic path, which is a Unix Domain Socket path, is on your X-server machine (here, Linux). If you read up, indeed that is where X should be listening. So what gives that ssh client has trouble connecting to it?
As
https://unix.stackexchange.com/a/57143 reveals, there's a thing called "abstract namespace" UDS, which
https://man7.org/linux/man-pages/man7/unix.7.html reveals to be a Linux-only thing. As
https://unix.stackexchange.com/a/735951 reveals, ssh doesn't support connecting to the abstract namespace'd UDS, and also provides a nice workaround: start socat on your Linux to forward the non-abstract UDS path to the abstract UDS path.
So, on a modern Linux, for this to work (maybe probably even from modern Linux -> Linux too, not just FreeBSD):
- fire up socat as hinted in that SO post:
socat UNIX-LISTEN:/tmp/.X11-unix/X${DISPLAY#*:},fork,reuseaddr ABSTRACT-CONNECT:/tmp/.X11-unix/X${DISPLAY#*:}
- and then do the
ssh -X.
