I tried removing “sudo” but it always asks for the password. i think at this point it is an ssh key problem. Is there a guide to follow to configure correctly?
Thanks for your answers I think I have installed the keys correctly, in fact if I try from the HA terminal to access SSH to the MacMini it works and does not ask me for a password. I needed to access via SSH to control the cameras via SecuritySpy software. I found a specific plugin and solved it. Thanks to everyone anyway!
I’m running HA as supervised (hassio) install on Docker on Raspbian (RPI 4A). As I use the RPI for gaming (steamlink) as well as media center (kodi) I need a way to switch between those when needed. I figured out that ssh’ing to console to run commands will be the best option here. I have ssh setup with personal keys already from my win10 PC. I have generated public key via hassio terminal as well. Even though I could not localize root folder somehow, I used cp to copy the id_rsa.pub to config/ssh. I have added hassio public key to RPI ssh known_hosts. I can ssh from hassio terminal without any problems (no password needed as I disabled it). When running shell_command from automation it does not work though.
All of above result with Error 255. When running from hassio terminal simple ssh [email protected] kodi works straight away.
I suspect it has something to do with user that is running those commands. I presume that running those from hassio terminal makes me acting as root (I think it is confirmed in ssh public key that I generated from terminal as it has root@core-ssh as acting user at the end of key. Automation will not run as root as I think . The thing is I have no idea what is the user that runs shell_command in automation. I have tried find something useful in Portainer data for both hassio_core and homeassistant containers to no avail.
Any hints to where should I place my next steps? Also sorry for this terribly long post.
Odds are high that the problem is your use of the public key in those commands The public key goes to the authorized_keys file on the remote host, the private key is the one you use when connecting.
Thanks for quick reply! And well… that’s a really good point! Networking is total magic to me.
I have cp’ed the private key to /config/ssh folder and tried to run commands again with it. Though again Error 255 pops up. I have wondered whether quotation marks have something to do with that as I have seen mentions on that above (though as I’m running simple “kodi” command I guess that no quotation marks should be required, right?), but that’s still not that.
To recap so it might be useful for somebody looking for answer:
Supervised install running on Docker on RPI.
Keys generated in Hass.io terminal (not RPI terminal) (addon Terminal & SSH used here) via ssh-keygen command.
Keys copied to /config/ssh via cp /.ssh/id_rsa /config/ssh/id_rsa and cp /.ssh/id_rsa.pub /config/ssh/id_rsa.pub (in Hass.io terminal)
Pub key (id_rsa.pub) copied to PI’s home/pi/.ssh/known_hosts
SSH settings edited not to use password auth (note that if you use different machines to ssh to PI you will need to add them by public key as well, you will not be able to log in with password after that). Edit /etc/ssh/sshd_config with: PasswordAuthentication no
Command run with use of priv key (id_rsa) - in my case command is: run_kodi: ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] kodi
Aaand that’s it I guess. Hope that I didn’t miss anything. Thanks again Tinkerer for help. I finally kinda understand how priv and pub keys in ssh work. Next task - figure out how to shut kodi down from terminal without ending up with black screen . That’s totally separate topic though.
Hi, I also have home assistant installed on Docker running on RPI. I followed your steps and it worked perfectly when launching the following command from Terminal&SSH add-on: