I'm trying to run gparted on my Raspberry Pi. After logging in with ssh -X pi@pi and trying to run sudo gparted, I get the error message...

X11 connection rejected because of wrong authentication.

When I try xauth list, nothing is shown, meaning that the xauth file is missing. What is the easiest way of getting the X11 forwarding to work?

Edit: I tried the suggestion from below, but the first step already fails:

root@raspberrypi:~# xauth list $DISPLAY

xauth: file /root/.Xauthority does not exist

How do I generate this file?

  • 1
    Is there actually an X session to forward the remote session to? You're not doing this in putty are you?! – Jivings Aug 26 '12 at 21:03

A convenient way is to use the gksudo command instead. (From the debian package "gksu").

  • Yeah, this is probably a better, easier solution. – Jivings Aug 26 '12 at 10:44
  • I tried solutions using xauth and similar stuff but this was the only solution that actually worked for me! – Hiura Oct 17 '16 at 9:02

The problem is that the X session for the superuser doesn't know what the cookie is.

After logging into the Pi execute the following:

$ xauth list $DISPLAY 

This prints the cookie, something like this:

pi:10 mit-magic-cookie-1 4d22408aga55sad1ccd165723g77923ae

Then switch the superuser with su and set the cookie:

# xauth add pi:10 mit-magic-cookie-1 4d22408aga55sad1ccd165723g77923ae 

X-forwarding should now work for root.

  • Is there an arguement you can pass to sudo? – Alex Chamberlain Aug 25 '12 at 21:33
  • @AlexChamberlain Not that I know of. – Jivings Aug 26 '12 at 10:43
  • This doesn't work, unfortunately. See my edit in the original post. – Eekhoorn Aug 26 '12 at 16:46
  • 1
    @zenbomb It appears you ran xauth list as root, which of course fails. You want to list the cookies for the user and add them for root. – XTL Aug 27 '12 at 6:41
  • xauth merge is so much more convenient than xauth list followed by xauth add. – Jon Watte Oct 27 '17 at 0:45

So I had the same error:

xauth: file /root/.Xauthority does not exist

when trying to add the cookie to the root account using (example only)

xauth add pi:10 mit-magic-cookie-1 4d22408aga55sad1ccd165723g77923ae 

I solved this problem by creating the /root.Xauthority file (logged in as root):

touch /root/.Xauthority

The command touch creates an empty file. I hope this helps.



1. ssh mitter@host'

2. $ sudo su

3. # xauth merge /home/mitter/.Xauthority

Configure $DISPLAY variable, if it is not configured.

  • 1
    what is mitter? – Steve Robillard Oct 6 '15 at 18:53
  • "mitter" is his particular user name. What user name you want to merge depends on what system you're running, and what user you're logging in as initially. On a Raspberry Pi, the default user name is "pi." On many Ubuntu installations, the default user name is "ubuntu." – Jon Watte Oct 27 '17 at 0:44

i fixed it with a symbolic link:

ln -s /home/[my username]/.Xauthority /root/.Xauthority
  • Bad idea. That will create a permissions problem for [username] if you use the root account with X. – goldilocks Oct 9 '15 at 17:41

i just cp'ed the .Xauthority from /home/user to /root

  • 1
    This is officially frowned upon because it establishes bad habits which get you in trouble on multi-user machines. Works like a treat on single user machines. – hildred Dec 26 '14 at 12:51

protected by goldilocks Oct 9 '15 at 17:42

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.