- You have to configure sudo (for user openhab) not to ask for password.
- you have to use sudo as user openhab once through the console, as sudo will once ask for the knowledge, that with great power comes great responsibility.
The first point can be covered by using visudo and add a line like that:
openhab ALL=(ALL:ALL) NOPASSWD: /sbin/reboot, /sbin/poweroff
That will allow user openhab to use /sbin/reboot
and /sbin/poweroff
without typing a password. You have to use absolute paths, and it’s not a good idea to just allow all commands to be executed
the second point is a bit tricky, as openhab per default has no bash to login (for security reasons), so you have to force login:
sudo su -s /bin/bash openhab
sudo
will ask you for yorur password (as openhab has none, and you can’t login without a password)
su
will provide a login, using /bin/bash
as console for user openhab
. As su is started as user root, there will be no question about passwords.
Now you are logged in in a console as user openhab. just start sudo once:
sudo ls /
and sudo will give you a short message:
openhab@openhab2:/root$ sudo ls
Wir gehen davon aus, dass der lokale Systemadministrator Ihnen die
Regeln erklärt hat. Normalerweise läuft es auf drei Regeln hinaus:
#1) Respektieren Sie die Privatsphäre anderer.
#2) Denken Sie nach, bevor Sie tippen.
#3) Mit großer Macht kommt große Verantwortung.
[sudo] Passwort für openhab:
(Sorry, german version…)
In fact, you won’t be able to execute this command, as it’s not in the nopasswd list, but the message is sent once, and that’s all. Try
sudo /sbin/reboot
and see if it works as intended.