Home > Back-end >  Can I talk to the X server by mounting .X11-unix remotely?
Can I talk to the X server by mounting .X11-unix remotely?

Time:11-09

This is just a conceptual question to test if I understand how X works.

Let's I have an X server running on machine A. If I make a new directory called /tmp/.X11-unix on on machine B, and use sshfs to mount root@A:/tmp/.X11-unix to root@B:/tmp/.X11-unix, would I be able to download statically compiled binaries on machine B that used X and see their display output on machine A?

When I tried this experiment, exporting the same DISPLAY variable on B as the one on A, I got the display unavailable error when trying out Portacle. I know that Portacle can display its output when working on a very minimal machine because when I run it on a busybox container, I can see the emacs window, so what is failing here? Does the problem lie in writing to a remote file or is something else missing on machine B?

CodePudding user response:

You cannot mount unix socket from one machine to another. (To be more precise, you can mount using sshfs, but socket will not work)

But you can connect two sockets on two machines via a TCP connection.

On machine A:

socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CONNECT:/tmp/.X11-unix/X0

On machine B:

mkdir /tmp/.X11-unix
socat UNIX-LISTEN:/tmp/.X11-unix/X0,fork,reuseaddr,unlink-early,user=$USER,group=$USER,mode=770 TCP:IP-address-of-A:6000
# Assuming user's group has the same name as user name.
# Remember to replace `IP-address-of-A` above

Now you can run DISPLAY=:0 xterm on another terminal of B.

CodePudding user response:

First off X is network based. Not file based, so you're missing a large chunk of the picture.

The X server is the software that displays windows etc - it is running on the "box in front of you" (machine B). The X client is your program. It can run on machine A with it's display set to machine B.

  • Related