Hi, I see I’m not alone with SSH commands not working from HA GUI but I also don’t see a working solution. Goal is to set an automation to reboot an ASUS router in the morning.
Problem: shell commands DO work from Terminal addon but DO NOT work from HA GUI or automations.
RSA key pair is pasted to the router’s web admin. I understand HA and Terminal addon are probably two different users with different credentials but I don’t know how to fix it.
Not what you might want to hear, but I am in the same boat here. I am attempting to reboot a remote raspberry pi with the shell commands without much success.
First, you need to use SSH & Web Terminal which can be found on the Home Assistant Community Add-ons.
This lets you log on to the home assistant host (I think?)
Then i created the SSH keys from there and copied them onto the rasberry pi.
I then used this shell command to send commands to the pi.
picommand: ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] '[remote command to be run]'
I hope this helps, i should have documented what i did to get it working before i forgot. The key way to use the community SSH add on and not the official ssh add on.
Been having a heck of a time with this. I’ve copied the SSH keys to my raspberry pi and can execute the command when I open the SSH & Web Terminal without any problems. However, running this from a service doesn’t do anything. It gives me a return code: 255 in the logs.
Again, pasting this directly into the terminal executes with no problems.
EDIT: ok, apparently the keys HAVE to be in /config/.ssh not /root/.ssh. Copied my keys from root to config and changed the script to reflect those changes and I’m good to go.
I must be getting grey hairs on this… well more than I already have.
I had this working previously on an older version of both HA and Rasbian, but now I’m pretty much stumped. What I have done so far is:
generated the key on the HA
copied the key to the Rasbian
put in the shell alias to a bash .sh file
verified that I can connect from HA to Raspian with ssh and the key file
created a .ssh in /config and moved the files there, reflecting that in the script
set the correct rigths on the directory and the files
reverified in the terminal
made the automation
testfire of the automation
getting 255 errors along the way that I did various things
So now I have no idea anymore and the logging is not fantastic.
When I run it in the terminal, everything works fine… I’m at the end of my rope here.
Hi every one,
I am still having problem on using shell command on my home assistant.
I have home assistant installed on proxmox with ip 10.10.10.10 on a vm 10.10.50.22.
I been able to ssh in my home assistant core :
ssh [email protected]
than i created a key with:
ssh-keygen -t ed25519
and saved in /root/config/.shh
than i copied the key to the server i want send the ssh command line:
ssh-copy-id [email protected]
the command line i saved in my home assistant config .yaml is :
ssh -i /root/.ssh/id_ed25519 -o ‘StrictHostKeyChecking=no’ [email protected] -i /config/.ssh/id_ed25519 ‘echo -n mem > /sys/power/state’.
I still get the error return code: 255
how can i solve ?
The ssh command returns that the connection was closed as a stderr output.
So just set logger level to debug to check it and if it works then leave it.
Perfect answer.
StrictHostKeyChecking=no AND key must be in /config/.ssh/. That solved it for me.
Thanks so much @mattbrad2 , even 4 years after, this is still the best answer.
I’m having terrible trouble with this and would love assistance if anyone could help.
Running Hassio on an intel NUC
I’m trying to shut down a readyNAS remotely.
Using the code from Terminal & SSH works fine
I’ve copied the id_rsa file cp /root/.ssh/id_rsa /config/.ssh/id_rsa
but running the shell command from HA still gives Permission denied (publickey). 255
The logs give me:
Error running command: ssh -i /config/.ssh/id_rsa [email protected] rnutil rn_shutdown, return code: 255
NoneType: None