20

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?

Eekhoorn
  • 301
  • 1
  • 2
  • 5
  • 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

6 Answers6

13

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

sourcejedi
  • 231
  • 1
  • 4
10

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.

Jivings
  • 22,538
  • 11
  • 90
  • 139
5

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 missing /root/.Xauthority file (logged in as root):

touch /root/.Xauthority

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

Greenonline
  • 2,740
  • 4
  • 23
  • 36
nagalman
  • 51
  • 1
  • 1
1

Solution:

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 06 '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 00:44
-1

i fixed it with a symbolic link:

ln -s /home/[my username]/.Xauthority /root/.Xauthority
-2

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