Ubuntu – Don’t gksu/gksudo or launching a graphical application with sudo work with Wayland


I installed Ubuntu 17.10. Now I am having trouble with gksu:

$ gksu -dg synaptic
No ask_pass set, using default!
xauth: /tmp/libgksu-HgUjgQ/.Xauthority
STARTUP_ID: gksu/synaptic/8760-0-alex-XPS-15-9530_TIME4974977
cmd[0]: /usr/bin/sudo
cmd[1]: -H
cmd[2]: -S
cmd[3]: -p
cmd[5]: -u
cmd[6]: root
cmd[7]: --
cmd[8]: synaptic
brute force GNOME_SUDO_PASS ended...
Yeah, we're in...
Unable to init server: Could not connect: Connection refused
(synaptic:8767): Gtk-WARNING **: cannot open display: :1
xauth: /tmp/libgksu-HgUjgQ/.Xauthority
xauth_env: (null)
dir: /tmp/libgksu-HgUjgQ

If I don't use -g, the password dialog is disabled. So looks like a problem with creating a tty for root.

Any advice?

Best Answer

  • Note this answer is specific to versions of Ubuntu using Wayland, 17.10 being the first release to use Wayland by default.

    It is a feature not a bug! It is a design feature of Wayland that you can not start graphical applications as root from the terminal.

    The main discussions are of course on the Fedora sites. See Fedora bug #1274451 and Graphical applications can't be run as root in wayland (e.g. gedit, beesu, gparted, nautilus) on Ask Fedora. But there is some discussion on the Ubuntu sites as well (Ubuntu Devs Uncertain about Using Wayland by Default in 17.10 - OMG! Ubuntu).

    Ubuntu bug report: Unable to launch pkexec'ed applications on Wayland session

    Potential work around - If you are editing system files with a graphical editor (such as gedit) use a command line tool such as nano or vim or emacs. nano is typically easier for new users, vim is more powerful and has more features, see this Vim Tutorial or similar.

    At any rate , if you really want or need to run graphical apps as root, set xhost first which forces fallback to Xserver.

    To set permissions run:

    xhost si:localuser:root 

    When you are finished, to remove permissions

    xhost -si:localuser:root 

    You can add a graphical / desktop option to do this as per this synaptic bug report

    pkexec'ed applications may be healed with xhost +si:localuser:root placed in XDG autostart as follows (N0rbert's idea):

    cat <<EOF | sudo tee /etc/xdg/autostart/xhost.desktop
    [Desktop Entry]
    Comment=Fix graphical root applications
    Exec="xhost +si:localuser:root"

    You could add this xhost command to .bashrc, but I would advise a pair of aliases

    alias gsuon='xhost si:localuser:root'
    alias gsuoff='xhost -si:localuser:root'

    You can name the aliases whatever you wish.

    For details see:

    Switch back to Xorg

    If you prefer Xorg for any reason, you can select to run on Xorg at login

    See How do you switch from Wayland back to Xorg in Ubuntu 17.10?

  • Related Question