Ssh shell_command not working

I’m trying to shut down my qnap nas from my Home Assistant.
To do so I thought to use a shell command.

First I configured keys to permit to login via ssh without password.
Then I tested the command from Home Assistant ssh, the command is this:

ssh [email protected] 'poweroff'

All goes well.

Lastly, I set up the shell_command:

shell_command:
  poweroff_nuvola: ssh [email protected] 'poweroff'

After reboot, if I try to execute the command using “services”, I find this in the log:

Error running command: `ssh [email protected] 'poweroff'`, return code: 255

NoneType: None

What could be wrong?

I use pretty much the same but mine looks like this:

shell_command:
  poweroff_nuvola: 'ssh [email protected] poweroff'

Also, what platform do you run HA on? Which installation method/operating system/etc.?

I tried removing the ’ but it stii doesn’ t work.

I have Hass.io installed on a raspberry 3 using this guide:
https://www.home-assistant.io/getting-started/

what kind of installation do you have?

Is your Raspberry Pi showing on your network. If so a simple thing you could do is pop your SD into a card reader, create a blank text file and save it as SSH without an extension and drop it into the /boot folder of your SD card. That will enable ssh for you.

I can “ssh” my Raspberry, didn’t need to create the blank text file:

Should I change the type of installation of my hass.io?
I understand I choose the very base one.

I’m trying to execute a ssh command with shell_command, but I’m getting an error 255 which I think is due to permissions relating to where the command is coming from.
If i ssh into the hassio machine, and try to ssh into the target, I need a password. I can set up key based login but it only works from the hassio shell.
If I use the terminal addon, I need to set up a new key based login as the other won’t work with it (is it because it is a separate container?).
Based on the above, I am assuming I need another key in the homeassistant container to be able to use the shell command, but I can’t figure out how and where to create that one.

Edit: found another post that showed I had to move the keys to config and then pass that location to the ssh command as ssh -i /config/ssh/id_rsa user@ip "command" but still getting an error

It seems I’m having a very similar problem as @SteveM363 - I have an automation that calls a shell_command, yet fails with the same 255 error previously mentioned. I’ve taken the same steps to move the key and reference it in the shell script but alas, the same results.

Here’s what I’ve been able to learn:

  • executing just a simple ssh -V from the script succeeds - I can prove this by directing the output to a text file as well as viewing homeassistant.log
  • executing ssh user@remote-host command will succeed from the command-line (when run either as root or with sudo) but will fail with a 255 in homeassistant.log
  • adding the -E outfile.log directive to the command results in the message “Host key verification failed.” regardless of whether or not I reference the key using the -i directive

Not trying to hijack a thread, just hoping I can help solve the issue. Ultimately I’m just trying to accomplish the following:

  1. Roku changes state by going into screensaver mode
  2. HA recognizes the state change and triggers an automation with a shell_command
  3. shell_command sends an ssh command to change the input on the TV to display something useful

I’m happy to provide any other info that would prove helpful.

I gave up, I was trying to reboot a pi if a sensor failed but was unable to get it done.
As it is a rare case, it usually is stable for months, I haven’t pursued it too hard.