5

Since I've upgraded to Ubuntu 18.04 I am no-longer able to do something like:

sudo su -

gparted

because now root can't access Display:0 and I've not found a way round.

Does someone knows how to get around that problem?

With gparted it isn't that bad but I use some other programmes where it doesn't works at all, as I have not got another program for doing the same. I don't want to start all as root, because I would know how to do this.

1
  • Side note, but please consider using sudo -i instead of sudo su -. One tool can become root just fine. ;)
    – Totor
    Jan 7, 2023 at 2:27

3 Answers 3

1

There is kdesudo, gsudo (I think), and some others.

Or you can copy this to ~/bin/xsudo

#!/bin/bash

inner() {
    su  - "$user" -c "xauth list" |
        grep "$(echo "$display" |
                cut -d ':' -f 2 |
                cut -d '.' -f 1 |
                sed -e s/^/:/ ) " |
        xargs -n 3 xauth add &&
        "$@"
}

if [ "$1" = "---innermode" ]
then
    shift
    user="$1"
    display="$2"
    shift 2
    inner "$@"
else
    self="$0"
    sudo "${self}" ---innermode "$USER" "$DISPLAY" "$@"
fi
4
  • Working but unwanted side effect: this made the .Xauthority file owned by root in the user home directory. Another call to xauth list as the user yields: xauth: /home/fabien/.Xauthority not writable, changes will be ignored. And now, the subsequent xauth list calls just hang on my machine.
    – Totor
    Jan 6, 2023 at 13:47
  • I just had a read of the code (not re-tested). Did you change the case of any of the words? (upper / lower case does matter). I can see how you would get the problem if you mess up the case. Jan 6, 2023 at 23:04
  • I changed the sudo line with su -c '"$0" "$@"' root -- "${self}" ---innermode "$USER" "$DISPLAY" "$@" because I don't have nor want sudo installed on my machine. Do think that could be the issue? I just tried it, and it does it again with just this line changed.
    – Totor
    Jan 7, 2023 at 2:22
  • I was thinking, this may be an environment problem, so I added -l option to su and got: xauth: file /root/.Xauthority does not exist / xterm: Xt error: Can't open display: %s / xterm: DISPLAY is not set. And the second time, same error, without the first line saying .Xauthority is missing. At least, in the previous version, the graphical application was working. :P
    – Totor
    Jan 7, 2023 at 2:34
0

You can use pkexec to run a GUI application as root.

$ pkexec gparted

Or:

$ pkexec bash
# gparted

pkexec uses PolicyKit for authorization, so you might need to get a PolicyKit in place to allow your user to run commands using pkexec. See the man page for more details on authorization.

3
  • pkexec gparted isn't working like sudo su - The connection to Display:0 is not working and the program stops as well. Nov 11, 2018 at 17:09
  • @AndreasBartels Try sudo -H? This thread suggests it might work in some cases...
    – filbranden
    Nov 11, 2018 at 17:23
  • problem still with sudo -H gparted there and I tried other programs - Problem still existing. Nov 11, 2018 at 17:32
0

If you are logged into a X session as a regular user who has sudo rights, then simply opening a terminal and using sudo gparted will work just fine.

The su command behaves differently, and while it does allow you to become another user or run a specific command as another user, it does prevent connecting to your X server.

5
  • I was telling in the first step, that for gparted it isn't that important, as there is a way round but I've got other programs that has the same problem and that are not running this way round. Nov 11, 2018 at 18:33
  • @AndreasBartels - this method Just Works for me for anything I've tried - zenmap, gparted (off live cd), etc. Can you give some example apps that don't work using this method?
    – ivanivan
    Nov 11, 2018 at 18:51
  • every Version 16.4, 12.4, 10.4 has worked this properly. now it's a bad thing, as I don't want to start as root at all. sudo gparted isn't working as this was something I tried first. Same fault. I wouln't come up with such a question if the basic function would work. But I found gparted not more usable. Some how I know that I did need it sometimes when there was a special situation with disks, as the program disks isn't doing all what you want, how you want. Nov 11, 2018 at 19:14
  • @AndreasBartels sudo su - followed by gparted isn't the same as sudo gparted - have you actually tried my suggestion?
    – ivanivan
    Nov 11, 2018 at 21:28
  • I had before asking tried sudo gparted, sudo su , and than inline, sudo su - and than inline and sudo -H gparted. Aktually I get it working only if I log out and log in with GNOME and Xorg but this is only a way round as I found out, that I am not more able to remote a Server because I can't connect to the Display with x11vnc so even after reading the authority out of ps aux . Looks like a problem of gdm3 Nov 14, 2018 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .