Best way to upgrade privileges programmatically on different versions of Linux?

Is there a standard way (working through Linux distributions) to start a process (from another application) with a root password request to increase privileges?

I tried using gksudo (it is installed by default in ubuntu), but in other distributions (or under a different desktop manager) it cannot be installed.

+1
source share
4 answers

This works everywhere, but does not cache the password and asks for the root password, not the user password (as sudo does):

 su - -c command 

EDIT : not on ubuntu where root account is disabled. You probably need something like this:

 test -x /usr/bin/sudo && sudo command || su - -c command 
+3
source

I would recommend looking at PolicyKit , which most modern distributions use to accomplish this.

+3
source

The only thing by default is su text mode. Most distributions also have sudo installed.

Now on KDE-based distributions you will have kdesu , while on GNOME there will be gksu and gksudo . Machines in Kerberized domains have ksu .

You can try using /etc/sysconfig/desktop to see which desktop is the default.

+1
source

Traditionally, if your application needs to allow the user to elevate privileges, it installs its own single-task setuid executable file - that it performs the required task, instead of acting as a universal launcher.

 $ su - # cp `type -p id` /usr/local/bin/root-id # chown root:users /usr/local/bin/root-id # chmod 4750 /usr/local/bin/root-id $ /usr/local/bin/root-id ... euid=0(root) ... 

OTOH setuid executables were also a common source of security holes, so be careful.

+1
source

All Articles