Hi,
I am trying to turn off my ubuntu server remotely. Openhab is running on my raspberry and Openhab runs by “openhab” user. I could manage to ssh from rpi with openhab user without password, but when I run exec command I get the following error:
openhab User für sudo Scripte aktivieren!
sudo nano /etc/sudoers.d/011_openhab-nopasswd
openhab ALL = (root) NOPASSWD: /etc/openhab2/scripts/shutdown.sh
If you follow this Instructions… than you give the Openhab User on raspberry the access to sudo the shutdown.sh
Note: SSH with Keys must work…
Here an German Tutorial … if this not your Native Language… Search with Google for SSH with Keys
@nattila1 as explained in this thread you must first execute one sudo command as user openhab/openhabian from the command line to get root working with the exec binding. Or enable the bash for the user.
From your error I think the problem is slightly different than some of the suggestions. The error is from the ubuntu server not the openhab raspberry pi. This means that the ssh is working fine but the user called openhab on ubuntu doesn’t have root privileges. So you need to make sure the sudo is for the openhab user on the ubuntu server. You want the sudo as part of the command, there doesn’t seem any need to add it in font of the ssh.
Thank you very much for your suoport. Thank you very much for your suoport. I solved this issue the following way: First, by following this tutorial I managed to be able to login from rpi to server without password. It was a bit tricky because I couldn’t switch to ‘openhab’ user on rpi therefore I run every command as a different user in the name of ‘openhab’ user.
Then was able to login but I still couldn’t shutdown the server, and I always got the following error: Need to be root
On the server I modified sudoers with visudo command and added the following line to it: myuser ALL = NOPASSWD: /sbin/shutdown, /sbin/poweroff, /sbin/halt, /sbin/reboot
Now, via terminal I am able to shutdown the remote server: sudo -u openhab ssh myuser@192.168.0.17 sudo shutdown -h now
But cannot for the life of me turn this into an executeCommandLine rule
rule "Shutdown Firewall"
when
Item shutdownfirewall changed to ON
then
shutdownfirewall.postUpdate(OFF)
Thread::sleep(100)
executeCommandLine("sudo -u kris ssh kris@192.168.1.254 shutdown -h now")
end
This fails and ive tried just about everything other combination without success
"Shutdown Firewall"
when
Item shutdownfirewall changed to ON
then
shutdownfirewall.postUpdate(OFF)
Thread::sleep(100)
executeCommandLine("bash /etc/openhab2/scripts/firewall_shutdown.sh")
end