I need some help with automated execution of Karaf commands. I have the Osram Lightify binding in place, but after a couple of days it stops working. I need to restart the binding in order to keep it working.
But I struggle to execute the bundle:restart command in an automated way, for example via cronjob. I cannot find out how to provide the password via keys-file. I’m using openHABianPi 2.3.
Here’s what I tried:
sudo su
mkdir /home/openhab
chown openhab:openhab /home/openhab
cd /home/openhab
sudo -u openhab ssh-keygen -t rsa -f openhab.id_rsa
Then I pasted the public key to /var/lib/openhab2/etc/keys.properties:
karaf=AAAA...29tb0Z,_g_:admingroup
and left the existing entry commented out.
Then I tried to connect via SSH, but it kept asking me for a password:
You have few options. Ssh key shouls work out of the box once you have a proper configuration.
Last option is clear text authentication with sshpass -p 'YourPassword' ssh user@host.
Ssh client can accept also command to be executed - if you do not specify it then client will connect and then exit after time out.
If I understand my openHAB installation correctly, openhab is the user in whichs context the openHAB service is running. The account does not provide shell access. But I think accessing the Karaf console via SSH must be done with exactly that user.
I am not sure if this topic has been solved already. But it took me a while to solve it. And now I can do some nice shell scripting with the console w/o login. The following ssh request is using the id_rsa.pub certificate, which is the default setting. If your certificate is called differently, use the second variant
The way forward is to add the public certificate information from the id_rsa.pub file into the /var/lib/openhab2/etc/keys.properties in the following way
Old topic, but i have an issue now. I used to habe multible lines with openhab as user in my keys.properties file. Since Openhab3 only the last line will be accepted the others wont work anymore. Different keys per application:
Just for the record: I moved on to a more radical solution and reboot my openHAB system in case I detect problems in a monitoring job (which watches out for OOM situations).