Shut down an external raspberry from HA using the ssh shell_command

After countless attempts, I've run out of ideas. Here's the situation: I want to use a switch to send the SSH command to shut down a second Raspberry Pi. To do this, I've added the following shell command to the configuration.yaml.

shell_command:

  rocrail_off: ssh -i /data/.ssh/id_ed25519 -o StrictHostKeyChecking=no [email protected] 'sudo shutdown -h now'

I installed the "Advanced SSH & Web Terminal" extension in HA. When I enter the line of code there, the command is transmitted correctly and the external Raspberry Pi shuts down.

If I use the shell command with an input helper and an automation nothing happens with the raspberry. Any ideas?

alias: Raspi RocRail OFF
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_boolean.raspi_rocrail_off
    from:
      - "off"
      - "on"
conditions: []
actions:
  - action: shell_command.rocrail_off
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - action: input_boolean.turn_off
    metadata: {}
    target:
      entity_id: input_boolean.raspi_rocrail_off
    data: {}
mode: single

That is running it it's own environment. I am guessing it cannot find your ssh key path when you run this in the working path where the shell_command runs.

When you say /data/... I think since the working directory there is /config, so that becomes /config/data/... Shell Command - Home Assistant

This was one of my first approaches. But no success.
I checked it this way:

ls -al ~/.ssh
lrwxrwxrwx    1 root     root            10 Jun 30 17:32 /root/.ssh -> /data/.ssh

seemed to be kind of alias...

ls -l /data/.ssh
total 20
-rw-r--r--    1 root     root           130 Jun 30 17:32 environment
-rw-------    1 root     root           411 Jun 30 18:08 id_ed25519
-rw-r--r--    1 root     root            99 Jun 30 18:08 id_ed25519.pub
-rw-------    1 root     root           660 Jun 30 17:34 known_hosts
-rw-r--r--    1 root     root            94 Jun 30 17:34 known_hosts.old

the key seems to be saved in /data/.ssh. But it also work within the ssh terminal with /root/.ssh. Tried all combinations... no success.

The terminal container is not where the shell_command integration works.

Maybe the ssh integration can do this?

I understand... but the change to

shell_command:  rocrail_off: ssh -i /config/data/.ssh/id_ed25519 -o StrictHostKeyChecking=no [email protected] 'sudo shutdown -h now'

also no success... I think I’m giving up at this point. I’ve wasted too much time already.

Thank you for your help!

The integration will try this when you put that in the command...
rocrail_off: ssh -i /config/config/data/.ssh/xxx
You need to move the file or add a share to an external folder I think.

That was the right tip. I had already tried moving the .ssh folder from /data/.ssh to /root/config/.ssh. That always resulted in an error message. Once I disabled "safe mode" in the Terminal app, I was able to move the .ssh folder without any problems, and now the automation is working too. Thank you so much! :slight_smile: