Hi:
I have a HA Core installed on a PI 4 and I was interested in accessing trough SSH a OpenWRT to execute operations. However, outside HA Core everything runs well but inside HA Core no, I had the famous error 255. After some digging I managed that to work and I am putting here may experience.
The first phase is the normal one, I created the private and public keys using PuttyGen and I use the private on my SSH client and the public I upload it trough OpenWrt Luci Portal but copy it from the PuttyGen Screen APP because the generated file is not accepted by SSH on OpenWRT. IS according to my understanding format issues.
The private key I need to export it on PuttyGen as a OpenSSH format because the default format is not accepted by SSH client on PI 4. And I put the private key on /root/.ssh with its default name, id_rsa and the file permissions as 600, because if the files permissions was others this does not work. Must be access only by root.
So, with this the following line works perfectly
ssh user@ip ‘comand’ (The command inside comas)
However, if I try running this inside HA Core trough Shell Command this does not work. And, after some investigation I managed to do that with the following steps:
- The private key must be on another folder, a folder inside the homeassistant main folder, the /home/homeassistant/.ssh/id_rsa because the SSH client invoked by HA Core apparently can not access the key on /root/.ssh
- The permissions must be less restrictive, so must be 0664
- Copy the sshhosts file to this folder also.
And now the new commando will be:
ssh -i /home/homeassistant/.ssh/id_rsa user@ip ‘command’
The -i option tell do client to find the private key on another folder.
With this works perfectly.
Also, if you need to debug a little more I recommend the following command:
logsave /tmp/debug.txt ssh -v -i /home/homeassistant/.ssh/id_rsa user@ip ‘command’
- The logsave is an application that catches everything for stdout and write to a file, in this case on /tmp/debug.txt
- the -v option on ssh command tell ssh to enter in debug mode a write everything on stdout.
I hope this can help others because I did not find any help on this here and others places.
Best regards
CGR