Xauth
lastmod 2020-09-05created 2020-09-052 edits
xhost controls access using things like host names on the network, but when you want stricter access control, use xauth.
xauth uses an authentication string called a magic cookie. By setting the X server's cookie on the terminal that runs the X application, it serves as the key that controls access.
Print magic cookie
Extract
The X server's cookie is sent to the terminal that runs the client. Use xauth extract to create an xauth instruction file, then pipe (|) it and use ssh to have the target host run xauth merge, which registers it on the target host.