Score:0

How to hibernate from Gnome Shell Extension without password?

br flag

On my system (Ubuntu 20.04) I have installed this Gnome Shell Extension that modifies the style of the power-off options and also adds an option to hibernate, which I occasionally use on my system in place of suspend. While the extension works as expected, every time I want to hibernate, I am prompted for a superuser password in order to proceed, which is annoying. To get rid of the password dialog, I followed this answer and added

my_username ALL=(ALL:ALL) NOPASSWD:/bin/systemctl hibernate

to my sudoers. After this change, I am able to hibernate from command line without password, as expected. However, the corresponding option from said Gnome Shell Extension still prompts me for a password. The code behind the scenes of the extension can be found here. I was unable to find any implementation of the function Util.trySpawnCommandLine, but it appears that it would just call the supplemented command in a shell. Hence, it's not clear to me, why I am still asked for a password. I have checked that which systemctl returns /bin/systemctl. Could it be that commands from the Gnome Shell are executed in a different user context than the logged in user?

PS: Is it considered safe from a security standpoint, anyway, to add above line to the sudoers file?

br flag
There is a extension https://extensions.gnome.org/extension/755/hibernate-status-button/ this does not require root password. If you want to stick with the extension you mentioned.. tweaking that extension can do the job. I suggest you to try that extension, if that works, I can help to integrate the same to your installed extension.
ranguwud avatar
br flag
For me the extension, which you suggest, does not work. In Ubuntu 20.04, at least for me, there are no longer those circular buttons to power off. When installing the extension, nothing happens in the menu.
br flag
https://askubuntu.com/a/1260588/739431
starkus avatar
de flag
For me the extension does not work, too. And hitting `ALT+F2` and giving the `systemctl hibernate` command does not require any password by default. Did you install the extension system wide, or for user only?
starkus avatar
de flag
Oh, that was way too fast I guess. The extension does its trick for me without giving a password prompt.
br flag
@ranguwud "I am able to hibernate from command line without password, as expected." what is the command you are using `sudo systemctl hibernate` or `systemctl hibernate`. if the first one not asking password then you need to edit the extension.js file `Util.trySpawnCommandLine`. I have tested this in Ubuntu 20.04 and it worked. However my in my system `which systemctl` returns `/usr/bin/systemctl`
Nate T avatar
it flag
ALT+ F2 is a TTY. By default they run as login shells. The username pwd is the point in that case.
Nate T avatar
it flag
When you do something via an application, from the OS's perspective, it usually looks like the application is trying to execute the command. Therefore, the application, not your user acct. needs the proper group/ permissions.Apps have groups too. try adding the app's group to `sudoers`.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.