Send shutdown command to OTHER raspberry pi with exec?

I have a Raspberry pi running octopi for my 3D-printer. i’m looking for a way to send a SSH command to this pi with my openhab device.

i think it should be something like this:

executeCommandLine("ssh user@octopi-server 'sudo /sbin/shutdown -h now'",1000)

but it kind of obviously sends me a “Host key verification failed.”

user and root access etc in linux really is totally beyond me, i have no idea how to give my openhab server permission to execute commands on another server…

any pointers to what i could try?

You need to get the public key of the user that runs OH and import it to the authorize_keys file of the user user@octopi-server.

Have a look at Openhab to access other server via ssh to execute script this thread should give detailed instructions. If that is not enough please let me know.

thanks for the quick reply!
i managed to get the key to the other server. Only now im running into the problem that my openhab install does not have the rights to use SSH. Im running openhab on a Ubuntu machine, so my main system user is different to the openhab user.
ive tried all kinds of ways to give it access to SSH…
added openhab user to ssh_config, added openhab user to root group, but still “permission denied” error…

that should not be the case.
I suggest that you create a shell script that contains the ssh command that you would like to execute.
This makes it possible that you get around other items like the need to replace spaces with @@ in the command that you would like to execute.
Then try to run that script first from the command line.
Keep in mind that the command line user most probably ( 100% ) is not the same user as your openhab user. To get around this promblem in a simple way use a generated private/public key pair and use the option -i to let the ssh binary know that you would like to use a dedicated private key.

that is not a problem in your first post you described that you would like to remote connect to user@octopi-server.

as long as you did not change Ubuntu default configuration of ssh that is not required.
Adding user openhab to group root is also neither required nor a good idea.

Where do you get the ‘permission denied’ message ? Keep in mind you try to execute two items that could cause this message:

  • ssh command; it could be used that the wrong key is imported ( not the public key of OH user )
  • sudo; does the user@octopi-server have sudo privleges ?