X11 connection rejected because of wrong authentication when using sudo

5,380

Found an answer here: https://www.slothparadise.com/sudo-root-x11-connection-rejected-wrong-authentication/

For whatever reason, Xauthority isn't being passed over on sudo. But... sudo xauth merge ~/.Xauthority then sudo graphical-app works fine.

I think this is unrelated to ssh, just to Xauth and sudo.

Share:
5,380

Related videos on Youtube

ColinB
Author by

ColinB

Updated on September 18, 2022

Comments

  • ColinB
    ColinB over 1 year

    I have a headless server and a desktop client, both running XUbuntu 20.04.

    I log in to the server using 'ssh -X servername'

    Graphical applications work fine from the server as a normal user, and display on the desktop machine.

    But, when I 'sudo graphical-app' (eg 'eog', or 'update-manager'), I get the following error:

        X11 connection rejected because of wrong authentication.
        Unable to init server: Could not connect: Connection refused
    

    Similarly, 'sudo emacs' responds: [sudo] password for cmb:

        X11 connection rejected because of wrong authentication.
        Display localhost:10.0 unavailable, simulating -nw
    

    (and falls back to running emacs in the terminal).

    On earlier versions of XUbuntu (back to 12.04, through to 18.04 / 18.10 / 19.04) I was able to run graphical applications on the server through 'sudo' and they displayed correctly on the client. Something has changed! Any ideas as to what, and how to work round it?

  • copeland3300
    copeland3300 about 3 years
    One thing to note, per the original article, if you want to do this from an elevated command prompt, ie you ran sudo su or sudo su -, after elevating to root, you would run xauth merge ~/home/YOURORIGNALUSERNAME/.Xauthority rather than using the home dir shortcut ~ as the location (since ~ would now reference /root rather than /home/YOURORIGINALUSERNAME)