26

I wrote an answer advising the use of sudo -i nautilus. I know that gksu is deprecated, and I was under the impression that sudo -i is how we should run graphical applications as root without killing kittens, but someone commented 'pkexec is the new gksu'. My understanding is that pkexec is not the same as using any form of sudo:

When to use pkexec vs gksu/gksudo?

and requires setting up, especially to use with graphical applications:

How to configure pkexec?

When I do sudo -i everything always works, so why should I go to the trouble of configuring pkexec? I can see that for writing a script that launches something as root I would need to do it:

Can I use pkexec in a Python Script or .desktop file?

But otherwise, what do I gain from using pkexec? When should I use these commands? What is currently the best practice for opening graphical applications as root?

(I already read the... man pages, but I am feeling no wiser.)

7
  • 5
    I personally ignore the deprecation and always install gksu on every system to run GUI apps with gksudo if needed. Nothing else.
    – Byte Commander
    Commented Jul 25, 2016 at 10:43
  • 1
    Related: This old post on meta had relevant discussion and the most upvoted answer suggested sudo -i is a safe solution; But not much explained for pkexec.
    – user37165
    Commented Aug 26, 2016 at 9:19
  • 2
    In the case of using GUI text editors to edit files as root, what about using sudoedit (AKA sudo -e)?
    – edwinksl
    Commented Apr 16, 2017 at 12:20
  • 1
    @edwinksl you meant you could set a graphical editor as default for sudoedit? Interesting idea
    – Zanna
    Commented Apr 16, 2017 at 12:31
  • 1
    @Zanna Yeah, see unix.stackexchange.com/a/356443/6949 for example.
    – edwinksl
    Commented Apr 16, 2017 at 12:49

1 Answer 1

4

The basic use is the same - the programs in question allow you to run other programs as another user, usually root. The difference, however, between sudo variants and pkexec is that sudo gives a program total control over everything, while with pkexec you have a much more fine grained control by defining a policy for each program.

If you trust the programs that you run, sudo is perfectly fine. If you want to really lock down everything and permit programs to do only what you allow them to, then use pkexec that comes along with polkit.

While the idea behind pkexec is nice, I wouldn't go as far as calling it the next gksu, due to the complex set up needed.

Reference: the difference between sudo and pkexec on Quora.

You must log in to answer this question.

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