The exec binding will execute the string you give it on the local host in a child process of the openHAB server. The command you are asking the binding to execute is “sudo …” (the ssh-related arguments are for the sudo command). Are you trying to to “ssh sudo shutdown …” rather than “sudo ssh shutdown …”?
I don’t know how to interpret the log message you included without more context.
Thank you for your reply.
Do you know how i can get some more debuginfo from the logs?
The reason i use sudo is because the ssh server one the remote machine asked for password when not using the sudo to start the ssh connection. I realised that i used sudo when creating the key with ssh-keygen so the key was made for the root account.
I did it again (made the keys) and got i done correct so i removed the sudo, but i cant connect to the ssh server.
I have done som searching and found some information about folder/user permissions so i will have another look later tonight.
So what you are saying is that the machine where OH is running requires sudo to execute ssh? That seems odd but I’ve seen stranger things. However, what is common is to need sudo to execute shutdown which I think was @steve1’s point.
Assuming this is right, have you changed sudoers so a password is not required by openhab to execute ssh? Otherwise it will just sit there and eventually time out waiting for a password.
Assuming you are running OH on 192.168.0.105 this error means it timed out waiting for you to enter a password.
Have you set up your ssh keys so you can ssh to 192.168.0.106 without a password? If so have you set up the openhab user with those keys as well? Remember that OH runs as the openhab user, not pi or root or any other user you might have and running the command from manually.
The easiest way to debug these sorts of issues I’ve found are to convert the switch to a dumb switch, execute the command in a rule using executeCommandLine(cmd, timeout) (remember the timeout or else it won’t return anything) and log what it is printing.
I solved a tricky problem this way that was caused by the private key in openhab’s .ssh folder not having the right permissions. It worked fine from the command line even when I used runuser but when openhab tried to ssh it generated the error.
Here is my code for reference.
Items:
//Switch S_N_GarageMqttReporter "Reset mqttReporter on Garage" <network> { exec=">[*:/etc/openhab/configurations/scripts/resetGarageMqttReporter.sh]"}
Switch S_N_GarageMqttReporter "Reset mqttReporter on Garage" <network>
Rule:
rule "Reset Garage mqttReporter"
when
Item S_N_GarageMqttReporter received command
then
val String results = executeCommandLine("/etc/openhab/configurations/scripts/resetGarageMqttReporter.sh", 5000)
logInfo("Network", "Resetting garage mwttReporter. Results:\n" + results)
end
Once you figure out what the error is and correct it you can go back to the Exec binding on the Item.
Thank you!
I did set up ssh keys for both osmc account and the root account. I did also create keys for the openhab account BUT when you log in for the first time after creating a key you have to type yes/no!
You can not log in with the user “openhab” by default so i had to enable login and connect via ssh manually the first time.