Shell_command / ssh: return_code 255

Hi everybody,

I have this shell script below, that I can successfully run when I ssh into my hassos; it will work as intended, in this case, toggling audio playback on a remote linux machine.

However, when I run it through shell_command, I only get Error running command: /config/packages/cli_helper.sh "toggle_playback", return code: 255 , What do I need to change in order to make this work?

cli_helper.sh

#!/usr/bin/env bash

HOST="10.10.2.22"
USER="me"

ssh -i /root/config/security/hassos $USER@$HOST "/home/me/bin/ssh_geruest.py" "$1"

# vi: ft=bash

yaml

shell_command:
  unten_arbeitszimmer_drehknopf_toggle_playback: /config/packages/cli_helper.sh "toggle_playback"

EDIT: I also had it like this unten_arbeitszimmer_drehknopf_toggle_playback: '/config/packages/cli_helper.sh "toggle_playback"', no difference.


Again, I positively can ssh into my machine and run this; so both the identity file and the code itself must be correct. I ssh into hassos, run this code, and audio playback will toggle on my desktop PC.

I try running this through Home Assistant itself, and I get the error above. I have this in my configuration.yaml

allowlist_external_dirs:
  - "/config/security"

This directory seems to work fine as well; Home Assistant can write to it (via camera.snapshot) and access the files there (via notify.telegram).

These are the contents of that directory; it’s permission seem to be correct as well.

image

What am I missing? Thank you in advance for your help :slight_smile:

Here is a link you might find helpful

A couple of thoughts:

  • When you run it manually to see if it works, make sure you do so inside the homeassistant container and note that its config path is /config.
  • Follow the guide, as you’ll need an ssh option to deal with the fingerprint reply from the remote host
2 Likes

Thank you. I had to add -o UserKnownHostsFile=... to my bash script. Now it works fine, after copying the known_hosts file to my packages directory and pointing to it.

1 Like