I am trying to automate some stuff on my server. One of them is shutting down the server via a bash script without a password.

I've tried adding:

theuser ALL=NOPASSWD: /sbin/poweroff, /sbin/reboot, /sbin/shutdown

but I cannot shutdown the machine without having to enter a password....

theuser@server:~/Share$ sudo /sbin/poweroff
[sudo] password for theuser:
theuser@server:~/Share$ /sbin/poweroff
Failed to set wall message, ignoring: Interactive authentication required.
Failed to power off system via logind: Interactive authentication required.
Failed to open initctl fifo: Permission denied
Failed to talk to init daemon.

Is there any other way to do this in 20.04?

  • 2
    I would use the same as the desktop does: dbus. dbus-send --system --print-reply --dest="org.freedesktop.Hal" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Restart int32:0
    – Rinzwind
    Commented Aug 1, 2022 at 13:38

1 Answer 1


Figured it out... I'm now running 22.04 but this did work in 20.04

In visudo add the line:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .