Restart/Shutdown when running as non root user

On various Hardware and OS systems: pi / windows / routers / nas, etc

Moderator: leecollings

Post Reply
DomoticzCH
Posts: 6
Joined: Saturday 22 May 2021 7:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: CH
Contact:

Restart/Shutdown when running as non root user

Post by DomoticzCH »

hi all,

I'm running Domoticz 2021.1 on my Raspberry Pi Zero with DietPi OS (a very slimmed down Raspberry OS).

When DietPi installed Domoticz, it created a user called "domoticz", but by default he is not in the sudo group. So of course, he cannot shutdown or restart the system and you will see the following error when typing `sudo systemctl status domoticz.service` :

Code: Select all

May 22 08:06:31 DietPi domoticz[420]:     #1) Respect the privacy of others.
May 22 08:06:31 DietPi domoticz[420]:     #2) Think before you type.
May 22 08:06:31 DietPi domoticz[420]:     #3) With great power comes great responsibility.
May 22 08:06:31 DietPi domoticz[420]: sudo: no tty present and no askpass program specified
May 22 08:06:31 DietPi sudo[632]: pam_unix(sudo:auth): conversation failed
May 22 08:06:31 DietPi sudo[632]: pam_unix(sudo:auth): auth could not identify password for [domoticz]
May 22 08:06:31 DietPi sudo[632]: domoticz : command not allowed ; TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/sbin/shutdown -r now
May 22 08:06:31 DietPi domoticz[420]: Error executing reboot command. returned: 256
May 22 08:06:31 DietPi domoticz[420]: domoticz: Error executing reboot command. returned: 256
May 22 08:06:31 DietPi domoticz[420]: 2021-05-22 08:06:31.496  Error: Error executing reboot command. returned: 256
So what is the solution? You need to allow the user domoticz access to the shutdown command. For that, you need to edit the /etc/sudoers file with `sudo visudo` and add this line at end:

Code: Select all

domoticz ALL= NOPASSWD: /usr/sbin/shutdown
Hope this can help someone!
cimbali
Posts: 4
Joined: Friday 21 May 2021 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Restart/Shutdown when running as non root user

Post by cimbali »

Thank you, your post is helpful!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests