command to reboot as non-root user
The command run when your computer is running low on battery should be configurable through your desktop environment's GUI. Just open the settings app of whatever you use and look at the power options, you should have something like (this is on Cinnamon):
To make your user able to run these commands without entering a password, run sudo visudo
to edit /etc.sudoers
and add these lines (assuming your user name is martin
):
martin ALL=NOPASSWD:/usr/sbin/pm-suspend
martin ALL=NOPASSWD:/sbin/reboot
martin ALL=NOPASSWD:/sbin/shutdown
You can then run them with no password like so:
sudo reboot
Alternatively, and specifically for shutdown
, you can add your user to /etc/shutdown.allow
and then run shutdown -a
but that one does not work for Debian.
Related videos on Youtube
Tam Borine
Updated on September 18, 2022Comments
-
Tam Borine over 1 year
I am using LXDE on Debian. When logged in LXDE as user, I can click on the
logout
icon in the menu and choose one of the options:shutdown
reboot
logout
suspend
But when I type
reboot
orshutdown -r now
in the terminal, that does not work.How can I shutdown my system as the user from within the terminal? I need a command, which will be executed when my battery is critically low, so that my system can be shut down cleanly.
-
Admin over 10 yearsyou need to add the right to your user to use the command
poweroff
orshutdown
using visudo. -
Admin over 10 yearsCan't the power management software do things like that? It should be running with sufficient privileges already. I know apcupsd can be made to do it, because I use it to do it :)
-
Gilles 'SO- stop being evil' over 10 yearsBut you can click on the menu item in your desktop environment, even if you aren't a sudoer. You could trigger the same mechanism from the command line. (D-Bus, but I don't know what message to send.)