Do not run
sudo -u openhab reboot from openHAB.
`executeCommandLine(‘sudo -u openhab reboot’)’ is wrong.
It won’t work. It’s not needed.
You are already openhab so there is no reason to sudo -u to the openhab user.
IF you want to test that the openhab user is configured correctly from the command prompt, use
`sudo -u openhab sudo reboot`
But you will have to enter openhabian’s password when you run this command. If it asks for a second password it means you do not have openhab set up correctly.
sudo -u openhab in ANY openHAB Rules or Exec binding configurations.
I don’t think your problem is that sudoers is missconfigured. I think the problem is you don’t understand how sudo works.
When I log in everything I run is running as my login. Lets say I login in as openhabian. Then the command
reboot will be run as user openhabian. That will fail because
reboot has to be run as root.
So to reboot the machine as the user openhabian I would run
sudo reboot. This will make the reboot command run as the user root. I may or may not need to enter my openhabian password depending on the permissions granted in the sudoers to the openhabian user.
sudo runs everything after it as the root user. What if I want to run a command as some other user? That is what the -u option is for.
To run a command as the openhab user, I would use
sudo -u openhab <command>. I will have to enter the openhabian’s password here because I don’t think you can configure sudo to let you run something as another user without a password.
Now I want to see if the openhab user can run the command
sudo reboot without a password. I can’t log in as openhab so I need to change to the openhab user. So, if I take the command above to run a command as another user and replace
sudo reboot I end up with
sudo -u openhab sudo reboot
But like I said, you still need to enter openhabian’s password to run the command
sudo reboot as the openhab user. Now, if openhab is configured to run reboot with sudo without a password, then that will be the only password asked for. If you have configured it incorrectly then it will ask for a second password.
tl;dr Never use
sudo -u openhab inside openHAB. Only use
sudo -u openhab when you are logged into a command prompt as some other user and you want to see what the command will do running as the openhab user. You will always have to enter a password when using