4

I'm SSHing into my RPi, with X forwarding enabled. I'm trying to run gparted, but it seems to fail for me.

$ gksudo gparted
======================
libparted : 2.3
======================
The program 'gksudo' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadAccess (attempt to access private resource denied)'.
  (Details: serial 229 error_code 10 request_code 130 minor_code 5)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

or

pi@raspberrypi:~$ sudo gparted
X11 connection rejected because of wrong authentication.

(gpartedbin:21437): Gtk-WARNING **: cannot open display: localhost:10.0

If I run plain gparted, I get Root privileges are required for running gparted. in STDOUT, but I also get a dialogue box pop up. I've also run gksudo leafpad, which seems to work fine. How can I run gparted over ssh?

3 Answers 3

7

Make sure you have

ForwardX11 yes

in your local /etc/ssh/ssh_config

Now the problem is that when you sudo, you don't have the right credentials in .Xauthority. The -E option preserves your environment

so

$ sudo -E gparted
2
  • I use ~/.ssh/config instead, but, yes, as per the question, it is already enabled. Also (as per the question), X forwarding works fine when testing with leafpad.
    – Sparhawk
    Nov 20, 2013 at 4:15
  • Note that running programs with sudo -E will make them use your home directory (e.g. /home/pi), so next time you run those programs as a regular user, they will fail to run because their config files are owned by root. Nov 6, 2021 at 10:30
0

I had no luck with this:

ssh -X pi@mypi

but this worked:

ssh -Y pi@mypi
1
  • This is because you don't have ForwardX11Trusted=yes in your ssh_config. It's better to set it, because not only untrusted X connection only works with -Y, but it also expires after 20 minutes or so, making you wonder why your GUI apps suddenly stop working. Nov 6, 2021 at 10:42
0

gksudo is deprecated now. Having said that, if you're issuing commands manually, you can just use sudo instead.

Set the following options in your ssh_config:

ForwardX11 yes
ForwardX11Trusted yes

The first option alone will work, but keep in mind that untrusted X sessions expire after 20 minutes or so, making you wonder why your GUI apps suddenly stop working.

In order to provide access to the X display to the target user of sudo (typically root), you can copy your connection cookie from /home/pi/.Xauthority to /root/.Xauthority with

sudo xauth add $(xauth list | tail -1)

Avoid running programs with sudo -E, as doing so will make them use your home directory (e.g. /home/pi), so next time you run those programs as a regular user, they will fail to run because their config files are owned by root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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