andypnz
(Andrew Palmer)
January 12, 2025, 8:28am
1
Hi
Trying to run a ssh shell command (by script) from my HA (running on a RP5) to a Win11 box, to shut down the Win11 box.
Running this from HA terminal shuts down the PC:
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_ed25519 [email protected] shutdown /s
But running the below script to run this shell command does not work:
Shell command:
shell_command:
turn_off_yourpc: 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_ed25519 [email protected] shutdown /s'
Script:
alias: "Shutdown: Comp Room PC"
sequence:
- action: shell_command.turn_off_yourpc
data: {}
This is the error in HA log
Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/__init__.py:129
integration: Shell Command (documentation, issues)
First occurred: 9:14:34 PM (1 occurrences)
Last logged: 9:14:34 PM
Error running command: `ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_ed25519 [email protected] shutdown /s`, return code: 255
NoneType: None
koying
(Chris B)
January 12, 2025, 8:45am
3
andypnz:
-i /root/.ssh/id_ed25519
You don’t have a “/root” inside HA.
Your private key must be under “/config”.
andypnz
(Andrew Palmer)
January 12, 2025, 8:55am
4
Mine does
Also tried in /config/ - same error unfortunatly…
andypnz
(Andrew Palmer)
January 12, 2025, 9:11am
5
Hummm… not sure if you are suggesting something like this? No error (in HA log), but does not appear to do anything…
command_line:
- switch:
name: Computer Room PC Shutdown
command_off: 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_ed25519 [email protected] shutdown /s'
andypnz
(Andrew Palmer)
January 12, 2025, 9:16am
7
Thank you… I had seen that - however, I must be close, as it works from terminal So would be nice to be able to do this as a command line command.
koying
(Chris B)
January 12, 2025, 11:28am
8
andypnz:
Mine does
I meant that unless you use the Core installation (pure python), the “/root” of HA is not the same that on the host or on the Terminal addon.
Do you use Core?
andypnz
(Andrew Palmer)
January 12, 2025, 6:43pm
9
I am not sure what the ‘Core’ installation is…
I did start with the key in the /config/.ssh/ folder - when I am home from work, I will try /config/.ssh again… Thank you!
andypnz
(Andrew Palmer)
January 13, 2025, 4:21am
10
Changed to /config/.ssh/
From Terminal, it works.
From a shell command, unfortunately it still errors:
Logger: homeassistant.components.command_line.utils
Source: components/command_line/utils.py:36
integration: Command Line (documentation, issues)
First occurred: 5:16:56 PM (1 occurrences)
Last logged: 5:16:56 PM
Command failed (with return code 255): ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /config/.ssh/id_ed25519 [email protected] shutdown /s