Ubuntu – How to run an application with a GUI as admin from a non-admin user session

gksususudo

I defined 2 user accounts:

  • one with admin privilege (with sudo right) => lets call it adminuser.
  • a 2nd one without any privilege => lets call it normaluser
    and I configure the autologin on this 2nd user normaluser.

So when I open a normaluser session and want to run an application with admin privilege,
I open a terminal Ctrl+Alt+T and:

su adminuser
sudo anyapplication ...

It works fine, without having to quit the normaluser session (no need to open a adminuser session).


But what should I do if the application needs to run with a GUI (Graphic User Interface) ?
I though about that:

su adminuser
gksu anyapplication ...

but I get

** (gksu:9122): WARNING **: the connexion is closed
No protocol specified
No protocol specified
(gksu:9122): Gtk-WARNING **: cannot open display: :0.0

Best Answer

PAM can take care of it

This works for me on Ubuntu 16.04 (edit: it works too on 18.04 LTS):

put the line:

session optional pam_xauth.so

somewhere in:

/etc/pam.d/su

and/or

/etc/pam.d/sudo

and then doing "su -" or "sudo su -" I can use graphical apps as root.