Shell_command integration not working

I have the following shell_command integration set up in my configuration file:

#in config file
    execute_ssh: 'sshpass -p "sshpassword" ssh "[email protected]" "ssh command 1 to execute; ssh command 2 to execute"'

Calling this integration through the shell_command.execute_ssh service that becomes exposed does not work.

When I simply try entering the following string in the terminal add-on for home assistant, it works perfectly fine, as I see the result on the device I am trying to SSH into:

sshpass -p "sshpassword" ssh "[email protected]" "ssh command 1 to execute; ssh command 2 to execute"

For some reason, this command does not work through the shell_command integration. I have tried adding cd /root before the main command, as shown below, but it still does not work.

#in config file
    execute_ssh: 'cd /root; sshpass -p "sshpassword" ssh "[email protected]" "ssh command 1 to execute; ssh command 2 to execute"'

What are some possible reasons this integration is not executing the command that I have set? How should I go about trying to fix it?

Is there anything in the Home Assistant log when you call the service?

If you try setting up another shell_command that doesn’t use sshpass (just echo something, for example), does that work? I know that for ssh commands you often have to use the “StrictHostKeyChecking=no” option, not sure if that is relevant for sshpass.

Root doesn’t work like your typical linux distro.

Thanks for that, it makes sense that the commands were executing in the wrong container. I followed the steps in the guide and found that when my command was executing from the homeassistant container, it was throwing the error sshpass: command not found. So I went and installed sshpass within the homeassistant container with apk add sshpass, and it installed properly.

Running the commands from my earlier post directly within the homeassistant container (not the terminal add-on like I was doing earlier), initially did not work. The error is not being thrown anymore, but the command from my original post simply doesn’t do anything, and there was an error with return code 6 in my homeassistant logs.

Did some research, and this was due to the issue @EKC pointed out. So I executed command ssh -o StrictHostKeyChecking=no 192.168.X.X, and this IP was added to the list of known hosts.

After this, the command executing inside the homassistant container, and the shell_command.execute_ssh service that was exposed from the integration is working perfectly.

Thanks for the assistance, everyone.

1 Like