Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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").

share|improve this answer
Yeah, this is probably a better, easier solution. – Jivings Aug 26 '12 at 10:44

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.

share|improve this answer
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
@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

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.

share|improve this answer


1. ssh mitter@host'

2. $ sudo su

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

Configure $DISPLAY variable, if it is not configured.

share|improve this answer
what is mitter? – Steve Robillard Oct 6 '15 at 18:53

i fixed it with a symbolic link:

ln -s /home/[my username]/.Xauthority /root/.Xauthority
share|improve this answer
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

share|improve this answer
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.