command to reboot as non-root user

12,512

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):

enter image description here

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.

Share:
12,512

Related videos on Youtube

Tam Borine
Author by

Tam Borine

Updated on September 18, 2022

Comments

  • Tam Borine
    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 or shutdown -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
      Admin over 10 years
      you need to add the right to your user to use the command poweroff or shutdown using visudo.
    • Admin
      Admin over 10 years
      Can'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'
    Gilles 'SO- stop being evil' over 10 years
    But 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.)