One additional relevant piece of information that isn’t in the post @jimtng linked to (please read it because it is relevant overall) is that when you call executeCommandLine, the command is running as the same user that openHAB runs as, which is usually openhab. That is almost never the same user that you are logged in as so “via openhab cli I can connect to the server with” is almost irrelevant. The ssh key you’ve set up is unknown by the openhab user and you need to set up that user with the ssh keys and permissions and everything else it needs to run the command.
Ok, but for my understanding please explain.
I connect with user eg dirk to my other server via ssh from openhab console.
So why is there the user openhab involved?
The ssh key was created for user eg dirk. Why is openhab user important when the command get executed under another user on another server?
Thanks!
Because you are running the command as user openhab and the user you pass on the command line to ssh is the user on the other machine, not the local machine.
User openhab needs to have the ssh key.
Here’s an experiment you can run. On the command line:
sudo -u openhab
ssh dirk@192.168.178.180 ls
The first line gives you a command line running as the openhab user, same as what executeCommandLine gets.
You’ll get either a password prompt or a cert error depending on how the ssh server is configured when you run the second command.
Luckily to get that second line to work is probably as simple as copying the ssh public and private keys to ~openhab/.ssh which is going to resolve to /var/lib/openhab/.ssh. This directory does not already exist though, you’ll have to create it. And the cert files must be owned by user openhab and have read permissions for only the openhab user.
Once you can execute the command as user openhab on the command line, use the version of the call to executeCommandLine@jimtng posted above in post 5.