SH script runs in hassio SSH terminal but not as script HELP

I have a sh command that I want to run on the router when needed.

All is working if I open a terminal inside hassio ( termnal add-on) and run the command
ssh [email protected] “/bin/vbash -ic ‘restart igmp-proxy’”

When firing the shell_command it is not working

Running it in a cli it works. Running it in shell_command I wil get an error in the log 255 and with some command 127

This is what I did

Whoami -> root
ssh-keygen -t rsa
ssh-copy-id [email protected]
sudo -u hassio -H -s
Whoami -> hassio
ssh-keygen -t rsa
ssh-copy-id [email protected]

I tried the following commands into my shell_command.yaml. Just to see if any of them work. but none of them does

reset_tv: ssh [email protected] "/bin/vbash -ic 'restart igmp-proxy'"
reset_tv1: ssh -o 'StrictHostKeyChecking=no' [email protected] "/bin/vbash -ic 'restart igmp-proxy'"
reset_tv2: sudo -u hassio -H -s ssh [email protected] "/bin/vbash -ic 'restart igmp-proxy'"
reset_tv3: ssh -i ~/.ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] "/bin/vbash -ic 'restart igmp-proxy'"
reset_tv4: sudo -u hassio -H ssh -i /home/hassio/.ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] "/bin/vbash -ic 'restart igmp-proxy'"

Anyone?..

Taking them one at a time:

reset_tv: ssh [email protected] "/bin/vbash -ic 'restart igmp-proxy'"

Won’t work, because you don’t specify the key file, and because it’ll prompt about accepting the remote host’s key (and you’ll never get the prompt)


reset_tv1: ssh -o 'StrictHostKeyChecking=no' [email protected] "/bin/vbash -ic 'restart igmp-proxy'"

Won’t work, because you don’t specify the key


reset_tv2: sudo -u hassio -H -s ssh [email protected] "/bin/vbash -ic 'restart igmp-proxy'"

Won’t work, because there’s no sudo command (and also as above)


reset_tv3: ssh -i ~/.ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] "/bin/vbash -ic 'restart igmp-proxy'"

Won’t work, because the key file isn’t in /root/.ssh/id_rsa inside the HA container

reset_tv4: sudo -u hassio -H ssh -i /home/hassio/.ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] "/bin/vbash -ic 'restart igmp-proxy'"

Won’t work, because there’s no sudo and the key file isn’t there.


So, how do you solve this? "Easy"
  1. Create the key file with no passphrase
  2. Store the key file somewhere under /config/ - I suggest you create a folder for them in there (eg /config/ssh/)
  3. Specify the full path to the key file
  4. Tell SSH to accept new keys

Like this:

ssh -i /config/ssh/id_ed25519 -o StrictHostKeyChecking=accept-new [email protected] "/bin/vbash -ic 'restart igmp-proxy'

Thank you for your explenation. It is very clear now

So I copied all that is in /home/hassio/.ssh/ to the /config/keys

and changed the command
ssh [email protected] -i /config/keys/id_rsa -o StrictHostKeyChecking=accept-new "/bin/vbash -ic 'restart igmp-proxy'"'

Restarted Hassio and now all is working

1 Like