andypnz
(Andrew Palmer)
April 14, 2023, 10:43pm
1
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:
shell_command:
nas_shutdown: ssh [email protected] -oHostKeyAlgorithms=+ssh-rsa rnutil rn_shutdown
And this to scripts.yaml:
shutdown_nas:
alias: 'Shutdown: NAS'
sequence:
- service: shell_command.nas_shutdown
The log error is:
Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/__init__.py:117
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
tom_l
April 15, 2023, 1:16am
2
There may be some useful information here.
I’ve noticed there’s a significant number of posts looking for help on this topic and the posters all seem to struggle with a few common issues. I realized I’ve been almost copying and pasting my responses on these topics so it seemed like a good case for a community guide.
What will this cover
This guide will walk through the process of getting a command which ssh’s into another machine to get some simple data ready to be included in a command line sensor . To keep it simple I’ll use the same …
1 Like
andypnz
(Andrew Palmer)
April 15, 2023, 9:11am
3
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?
koying
(Chris B)
April 15, 2023, 9:43am
4
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)
e.g.
shell_command:
the_command: >
ssh -4 -o ConnectTimeout=3 -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa [email protected] '<command>'
1 Like
andypnz
(Andrew Palmer)
April 15, 2023, 8:16pm
5
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)
andypnz
(Andrew Palmer)
April 15, 2023, 9:57pm
6
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:
andypnz
(Andrew Palmer)
April 16, 2023, 1:51am
7
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…