I just upgraded my laptop and with that performed a fresh and clean installation of my OS of choice: Ubuntu. At the same time I came across Slimbook Battery 3: application for optimize battery of your laptop - SLIMBOOK Ultrabook, laptops, computers in this article on OMG! ubuntu!. I've been using TLP for a long time and Slimbook Battery is using it under the hood. This post offers a solution to the frequent password prompt when using slimbookbattery on Ubuntu by augmenting polkit policies.
I'm not reviewing the app here, but suffice it to say that the GUI on top of TLP is very attractive, as is the tray icon that makes changing power profiles quick and easy. However, on Ubuntu, it would prompt for a password every time I changed the profile, since it requires root level privileges. That was certainly annoying.
I tried using sudo, but was unable to get the password prompt to go away. The makers of the app even included a sudoers config in /etc/sudoers.d/sudo-slimbookbattery. Clearly, sudo was not the right tool.
After some more digging I found that the privilege escalation wasn't using sudo and instead was based on Polkit. The man pages for it are pretty dense, but in the logs I could tell that Slimbook Battery was using the pkexec call to fire up it's supporting scripts.
All that said, here's how to get Slimbook Battery to stop asking you for a password.
- Fire up an editor as
rootand edit the file/etc/polkit-1/localauthority/50-local.d/03-allow_slimbookbattery.pkla - Put the following in that file:
[Allow slimbookbattery]
Identity=unix-group:sudo
Action=org.freedesktop.policykit.exec
ResultActive=yes
- Save the file and enjoy. Nothing seems to need to be restarted.
Basically, this allows all users in the sudo group, which includes the user created during install, to call things via pkexec aka the org.freedesktop.policykit.exec action. You can restrict this further by forcing it to just a single unix-user or add extra spice and lots of power by changing the action to *.