authenticationdockerx11-forwarding

X11 forwarding of a GUI app running in docker


First off: I have read the answers to similar questions on SO, but none of them worked.

IMPORTANT NOTE: The answer below is still valid, but maybe jump to the end for an alternative.

The situation:

What works:

Some setup info:

What does not work:

X11 connection rejected because of wrong authentication.

xterm: Xt error: Can't open display: host-ip-addr:10.0

Things i tried:

How can i just disable all the X security stuff and get this working?

Or even better: How can i get it working with security?

Is there at least a way to enable extensive debugging to see where exactly the problem is?

Alternative: The first answer below shows how to effectively resolve this issue. However: I would recommend you to look into a different approach all together, namely VNC. I personally switched to a tigerVNC setup that replaces the X11 forwarding and have not looked back. The performance is just leagues above what X11 forwarding delivered for me. There might be some instances where you cannot use VNC for whatever reason, but i would try it first.

The general setup is now as follows: -VNC server runs on machine A on the host (not inside a docker container). -Now you just have to figure out how to get a GUI for inside a docker container (which is a much more trivial undertaking). -If the docker container was started NOT from the VNC environment, the DISPLAY variable maybe needs ajdusting.


Solution

  • Ok, here is the thing:

    1) Log in to remote machine

    2) Check which display was set with echo $DISPLAY

    3) Run xauth list

    4) Copy the line corresponding to your DISPLAY

    5) Enter your docker container

    6) xauth add <the line you copied>*

    7) Set DISPLAY with export DISPLAY=<ip-to-host>:<no-of-display>

    *so far so good right?

    This was nothing new...however here is the twist: The line printed by xauth list for the login user looks something like this (in my case):

    <hostname-of-machine>/unix:<no-of-display> MIT-MAGIC-COOKIE-1 <some number here>
    

    Because i use the bridged docker setup, the X forwarding port is not listening locally, because the sshd is not running in the container. Change the line above to:

    <ip-of-host>:<no-of-display> MIT-MAGIC-COOKIE-1 <some number here>
    

    In essence: Remove the /unix part.

    <ip-of-host> is the IP address where the sshd is running.

    Set the DISPLAY variable as above.

    So the error was that the DISPLAY name in the environment variable was not the "same" as the entry in the xauth list / .Xauthority file and the client could therefor not authenticate properly.

    I switched back to an untrusted X11 forwarding setting.

    The X11UseLocalhost no setting in the sshd_config file however is important, because the incomming connection will come from a "different" machine (the docker container).