Command works from terminal, but not from script

Hi. I am trying to shutdown my ReadyNAS from HA.

Running this from HA terminal works:
ssh [email protected] -oHostKeyAlgorithms=+ssh-rsa rnutil rn_shutdown

But if I add this to config.yaml:

  nas_shutdown: ssh [email protected] -oHostKeyAlgorithms=+ssh-rsa rnutil rn_shutdown

And this to scripts.yaml:

  alias: 'Shutdown: NAS'
  - service: shell_command.nas_shutdown

The log error is:

Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/
Integration: Shell Command (documentation, issues)
First occurred: 10:24:57 AM (2 occurrences)
Last logged: 10:28:40 AM

Error running command: `ssh [email protected] -oHostKeyAlgorithms=+ssh-rsa rnutil rn_shutdown`, return code: 255
NoneType: None

There may be some useful information here.

1 Like

Thanks… useful link, and I setup ssh to a PC using that info…

I am able to shutdown a PC on my network using ssh from a HA script in scripts.yaml - so I think overall things are working.

I can shutdown the NAS from the HA ssh+terminal window.

But if I start

docker exec -it homeassistant bash 

Then it fails with
Permission denied (publickey)

It also fails if I try running it in scripts.yaml in HA as above

I am unsure where else to look?

I assume you are using RSA keys for login?
When doing ssh [email protected] as a shell command, inside the HA docker container, you don’t have any keys defined, so you must create some specific SSH keys inside /config and refer to it in your ssh command with -i (use > to avoid quote escaping hell)


  the_command: > 
    ssh -4 -o ConnectTimeout=3 -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa [email protected] '<command>'
1 Like

Yes, using RSA keys. They are copied to /config/.ssh/id_rsa

I am using HAOS. I can turn off a PC (from HA) using a ssh script (with the id_rsa key) - so I think the key is setup ok and accessible…

To turn off the NAS:
This works from a HA ssh+terminal prompt.
But form the ssh script in HA it does not…

`Error running command: `ssh -4 -o ConnectTimeout=3 -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa [email protected] 'rnutil rn_shutdown' `, return code: 255`

And if I run the same command in the ssh+terminal using
docker exec -it homeassistant bash (which I think gives the same environment as running a ssh script in HA?) I get:
Permission denied (publickey)

At a very basic command level:
Form HA ssh+terminal this works to log into the NAS:
ssh [email protected] -o StrictHostKeyChecking=no

But from a ‘docker shell’ (is that the correct term after running docker exec -it homeassistant bash) the same command results in:
Permission denied (publickey)

I updated the known_hosts file to be sure it is correct.

This is the difference I see when running the same command in ‘ssh+terminal’ and then in ‘docker shell’.

I think both commands should be using the same known_hosts and id_rsa files?

Or this command:

In my case solved using the -F flag with a path to an accessible config file…

Unsure why this is needed for the NAS and not for the PC…