Add sshpass to the supervised / docker container

For some automations it is necessary to use scripting. For ease of use I usually rely on sshpass. Unfortunately this is not part of the base package of most docker containers. E.g. I use sshpass for switching on my TV with a remote CEC command send to my RPi with Kodi via a script from HA:

#!/bin/bash
sshpass -p ‘your_password’ ssh -o StrictHostKeyChecking=no root@ip_of_your_kodi ‘(echo “standby 0” | cec-client -s -d 1)’

The script is activated by a button in HA, issuing the command remotely on the Kodi device. Same for switching off the TV or checking the status: ‘(echo pow 0 | cec-client -s -d 1) | grep "power status: "’

For this, I need sshpass in a HA docker container / supervised install. Currently I connect to the container and use:

apk add --update --no-cache sshpass

to install sshpass after every update. Would be great if it would be “on board” as standard. Helpful bash_scripts are TV status/switching, activating PoE on ports of a Unifi switch (e.g. ‘(echo “enable” ; echo “configure” ; echo “interface 0/15” ; echo “poe opmode auto” ; echo “exit” ; echo “exit” ; echo “exit”) | telnet localhost ; exit;’ - currently just working on Unifi Gen1 switches) and many more. Would be appreciate if sshpass could be integrated in the standard docker container for HA.

Hi, I have the same request. Did you ever find out how to do this?

The exact same thing happens to me. I have a bash script to connect via ssh to my firewall and restart it, all automatically from HA. The problem is that everything was working fine until last week I updated the HA core. every time I upgrade the HA core I have to go through these steps again.

Go to Settings → plugins → Advanced SSH & Web Terminal → Uncheck protection mode → reboot

Go to Terminal →

docker ps -a

(look for the CONTAINER ID of the Docker container which is called homeassistant and its IMAGE is [Package qemux86-64-homeassistant · GitHub](http ://ghcr.io/home-assistant/qemux86-64-homeassistant:2024.5.4))

sudo docker exec -it CONTAINERID /bin/bash
apk add --update --no-cache sshpass
ssh -o KexAlgorithms=+diffie-hellman-group1-sha1 -o HostKeyAlgorithms=ssh-dss,ssh-rsa -t [email protected]

yes

Type password

exit

Go to Settings → Add-ons → Advanced SSH & Web Terminal → Check protection mode → reboot

I have created a custom homeassistant image that includes sshpass.
This is the image: matssa/homeassistant-custom
If you ever need it updated to a new homeassistant version just send me a email since i don’t regulary look at forums. My email: [email protected]

This is the main reason I’m never going to use HA. My hardware, my home, my way.

To solve all this we can do 2 things:

  • write in the script itself that whenever it is executed always perform the installation of the sshpass apk so if we update the core and it is lost it reinstalls itself “apk add --update --no-cache sshpass”

  • To avoid the issue of having to add by hand the ssh fringerprint the first time we will launch the sshpass command saying that it does not ask you to confirm the fingerprint or create the known_hosts file " -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"

for that in the script that runs we will put:

#!/bin/bash
apk add --update --no-cache sshpass
sshpass -p "xxxxx_password_xxxxxxxxx" ssh -o MACs=hmac-sha1 -o KexAlgorithms=+diffie-hellman-group1-sha1 -o HostKeyAlgorithms=ssh-rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] "reboot"
1 Like