In Ubuntu 18,19,20 system hibernate
command requires sudo
for its execution:
"systemctl suspend" vs "systemctl hibernate" Permission
To disable password prompt systemctl hibernate
command should be added to sudoers list (/etc/sudoers.tmp
)
Use sudo visudo
command and add to the end of the file the following line:
<user_name> ALL=NOPASSWD: /usr/bin/systemctl hibernate
But now there is bug in Simpler Off Menu
extension. Hibernate is performed in it by systemctl hibernate
, not by sudo systemctl hibernate
as required. This implementation is in file [email protected]/extension.js
I created corresponding issue for this extension:
Bug in Ubuntu 20.04: Pressing [Hibernate] button asks to input password before performing hibernate
The last commit was made about 1 year ago. So the extension is not actively supported.
Below is the full details from the issue with workaround:
Expected behavior
Pressing Hibernate
button executing sudo systemctl hibernate
.
If there is appropriate user in sudoers list (/etc/sudoers.tmp
edited by sudo visudo
):
<user_name> ALL=NOPASSWD: /usr/bin/systemctl hibernate
hibernate action is performed immediately after pressing Hibernate
button.
Actual result
Pressing [Hibernate] button asks to input user password to perform authorization for the action.
In system log (less /var/log/syslog
) there is an error - "Failed to hibernate system via logind: Access denied":
02:51:06 gnome-shell[1983]: st_widget_get_theme_node called on the widget [0x564b127af6f0 Gjs_ui_popupMenu_PopupSubMenuMenuItem.popup-menu-item popup-submenu-menu-item:last-child ("")] which is not in the stage.
02:51:06 Tgnome-shell[1983]: st_widget_get_theme_node called on the widget [0x564b127b6d00 StWidget:last-child] which is not in the stage.
02:51:06 gnome-shell[1983]: st_widget_get_theme_node called on the widget [0x564b12781480 StBoxLayout ("")] which is not in the stage.
02:51:13 systemd[1735]: Started Application launched by gnome-shell.
02:51:13 gnome-shell[5729]: Failed to hibernate system via logind: Access denied
02:51:27 gnome-shell[5729]: Failed to start hibernate.target: Access denied
02:51:27 gnome-shell[5729]: See system logs and 'systemctl status hibernate.target' for details.
After entering the password hibernate action probably is performed by not systemctl hibernate
but some other command. I'm not sure but may be by pm-hibernate
or hibernate
commands - what is not recommended.
Difference between "pm-hibernate" and "systemctl hibernate"
A rather short answer to this would be that systemd is actively maintained, while pm-utils is not.
In fact, pm-utils has not been updated since 2010, so I would consider this software both ancient and obsolete.
It is advised to use systemctl from this point on.
Difference between "systemctl hibernate" and "hibernate":
hibernate command was replaced by systemctl hibernate. It is recommended to use systemctl hibernate. hibernate command is still available in the system for compatibility reasons.
In Ubuntu 18,19,20 system hibernate
command requires sudo
for its execution:
"systemctl suspend" vs "systemctl hibernate" Permission
In implementation of SimplerOffMenu
extension in Hibernate
button the handler uses
systemctl hibernate
, not sudo systemctl hibernate
which is required to fix this issue.
Fix
Change extension.js
file as follows:
function FuncHibernate(widget, event) {
Main.overview.hide(); try {
//fix start: added sudo
//Util.trySpawnCommandLine('systemctl hibernate');
Util.trySpawnCommandLine('sudo systemctl hibernate');
//fix end
} catch (err) {
Main.notify("Error " + err);
}
}
Fixed extension.js
file is here.
Workaround
To fix this problem in Ubuntu 20.04 after the extension already installed it needs to do the following:
Change JS script of the extension which was installed here:
/home/<your_user_name>/.local/share/gnome-shell/extensions/[email protected]/extension.js
(you can find location of extension.js
file by sudo find /* -name "extension.js"
)
Then add sudo
as described in the fix above and safe the file.
To apply the fix may be it will be enough just to save the file. I just in case performed the instruction from here:
- Disabled and enabled the extension,
pressed config button on the extension page
- Pressed
Alt
+F2
, entered r
and pressed Enter
- Logged out and logged in