The original post: /r/ubuntu by /u/Crafty-Sundae6351 on 2024-05-02 04:32:49.

This should be easy - but I’m stuck.

I’ve got a Python program that runs at boot. (cron job calls a shell script that does some housekeeping prior to launching the Python program.) When the program encounters a certain event I want to reboot the system. (This is a headless system. I’m the only user of it. So I have no issues with security and other users.) The program is not running as root. I’m using os.system(“<command>”) to execute the command from Python.

One method I found was to add my username in sudoers and authorize my username for no authentication for /sbin/reboot. When in Gnome (either from the command line or when running a one-line Python from the command line) /sbin/reboot works just fine.

But - with this headless program the error log is showing “Interactive authentication required.” when I try to execute /sbin/reboot. I presume when running in Gnome the system is seeing authentication has been provided, so /sbin/reboot works.

Any suggestions for how I can get Python to cause a system reboot when I’m not executing that program as root?

Thanks.