X11 Connection Rejected

April 28, 2022 

When switching to root after the typical SSH with X11 forwarding enabled this error can appear:

$ X11 connection rejected because of wrong authentication.
$ Error: Can't open display: localhost:10.0

The workaround seems to include copying the MIT-MAGIC-COOKIE-1 from the user who ssh'd in to the root user using xauth. Here's how:

First verify the $DISPLAY being used and list the MIT-MAGIC-COOKIE-1 used for it :

$ echo $DISPLAY
localhost:10.0
$ xauth list
srv001/unix:10  MIT-MAGIC-COOKIE-1  b7ff39ed41f66cfe8fe439ed99e582ba

Next switch to root and copy the whole line that was listed and then add it to the root profile:

# xauth add srv001/unix:10  MIT-MAGIC-COOKIE-1  b7ff39ed41f66cfe8fe439ed99e582ba

Now assuming everything is correct in the standard ssh_config the error should go away and a window will before forwarded through the pipe.

Samuli Seppänen
Ricky Cousins
Author archive
menucross-circle