Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
18
rated 0 times [  18] [ 0]  / answers: 1 / hits: 6135  / 1 Year ago, sat, february 4, 2023, 1:38:48

There are various tools for various desktops that aim to run a graphical application as root. gksudo, kdesudo, empower, etc...



But what if I'm writing a script that could be used on any Linux desktop? Is there an xdg-sudo of some sort..? A standard for getting sudo access in a desktop environment?


More From » sudo

 Answers
4

Following @Tachyons suggestion, I researched a LOT about pkexec and it is awesome!



  • It is part of PolicyKit, a widely used package.

  • Hosted and sponsored by freedesktop.org

  • Default in Gnome, Unity, MATE, Cinnamon, KDE, LXDE and XFCE, and possibly others

  • Works via D-Bus, so it's completely desktop-neutral, with a well-defined protocol.

  • In many DEs it is used in several services like login screen, shutdown/restart, disk management (udisks/automount) and so on.


So yes, it meets all requirements, and I guess it's the closest thing an "universal gksudo" can be.


That said, pkexecis the command-line front-end to PolicyKit. There are 2 basic modes of operation:



  • Simply run it as you would with sudo, and you get a nice GUI prompt:


    $ pkexec rm -rfX /




pkexec GUI prompt



  • Or create a PolicyKit authorization file for you application, drop it in /usr/share/polkit-1/rules.d, and it will allow a great deal of customization and security-related options, for example root access for certain actions only, no need of password for others, access limited to certain paths, etc. You can fine-tune your settings with amazing granularity.


[#32768] Saturday, February 4, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
musining

Total Points: 171
Total Questions: 124
Total Answers: 121

Location: Zambia
Member since Thu, Jun 25, 2020
4 Years ago
;