Just spent a frustrating hour trying to get a simple ssh command to work across my network. No joy.
Is this never going to work because the docker instance can’t authenticate using the keypair I’ve created - and I basically need to use developer level access to enable ssh login to the hassio user etc etc?
Thanks!!
what are you trying to do with ssh that the ssh add-on can’t do?
Ah - is this the SSH & Web Terminal add-on? Using that I might be able to do what I want to do? Installing now!
Basically all I want to do is call a passwordless ssh session (i.e. using shared keys) to another server on my LAN and run a command. This isn’t working at the moment.
I don’t know if you can do this…
I’ve had a devil of a time with the ssh addon in the past and the console in the actual Home Assistant container.
I have had things work fine in the ssh addon that won’t work when I put them as a shell_command. The terminal/ssh is not ‘in’ the same docker container as Home Assistant. Even really basic things like a date command trying to return the time zone won’t work in the Home Assistant container but work in the ssh terminal.
Your best bet, and how I got around the date BS was to use portainer and go to a console in home assistant. Then you can work out what does and doesn’t work. But anything you want to run in a shell script MUST work in the Home Assistant container console or it won’t work. At least then you won’t be flying blind.
Thanks for the Portainer tip. I’ll see if I can try the SSH/web add on and failing that I’ll go portainer route. Who would have thought it would be so problematic!
The point I’m making is that even if it works in SSH/Web Terminal, it won’t necessarily work as a shell_command in the HA container… that’s why portainer console in the container is so useful… If you get it working there then the shell_command will work as well. I presume you want to make it a shell command and then run it with an automation?
Yep, I do, and I got/took your point, I just thought it was worth a go with the alternative ssh add-on first.
Nah, didn’t work - as you rightly suggested it wouldn’t. First it made me confirm the new fingerprint was OK, then it let me generate a new keypair for passwordless login to the other LAN host but again the command failed when clicked from within the HASS interface.
So Portainer it is! Thanks
at least you can investigate if there is any command that DOES work…
Trying to add SSH keys to the docker container can be a pain, I never got it to work.
I ended up using MQTT in the end for remote commands such as reboots and other things on remote machines.
Now you’re talking. MQTT was my first wish as well, but I couldn’t figure out how to cook up a simple “listener” on the remote device that would be resilient and survive reboots etc.
I looked up MQTT-Launcher and Bish-Bosh but I couldn’t get either of them to work and both seemed like overkill. Would love some help if you’ve done this already successfully…!!!
I actually have Node-RED installed on most of my Linux machines which is overkill but once it gets an MQTT message on the correct topic, it can the launch programs with the ‘exec’ node and many other things. It can even reboot if you set up sudoers
correctly. I have node-red launch on boot with a systemD service, and it doesn’t use a huge amount of resources.
I’m using mosquitto-clients also which allows you to send and recieve messages from the command line, it installs the mosquitto_pub and mosquitto_sub commands. If you are on debian just apt-get install mosquitto-clients
mosquitto_pub basically fires off MQTT messages from the command line.
mosquitto_sub is a listener which can subscribe to certain topics, I’ve not really used it much but it sounds like what you’re after, I would use it if I had a machine where Node-RED was not installled and need remote control.
Sounds like this might be the key to what I want to do. Thank you.
Node-RED sounds like overkill for my use (even though I installed it last night!) Just looks like quite a big learning curve for what should be a simple task!
Yeah if you have a MQTT broker setup this would be a good solution… I was using that to get data in from my ISP usage meter… but yeah hass.io doesn’t have mosquitto_pub so that didn’t work for me either… lol. But you can for sure publish from hass.io via a service so maybe that does what you want. (With a fixed payload)
(In case it sounds like I’m contradicting myself I was trying to publish a JSON string to MQTT broker vis a bash script and there is no mosquitto_pub in bash in the HA container so that didn’t work - although I could make it work with cron and a script in the debian system - I’m running hass.io as a generic Linux install on debian - that wouldn’t help anyone on HassOS as they wouldn’t have that option)
I’m using the Mosquitto add-on to Hass and using the Hass Pi as the Mosquitto broker and that works well. So now I just need to find a way to receive the MQTT and execute a shell command on the OTHER (non-Hass) Pi. Will do some more looking into it.
You should be able to use mosquitto-tools there to subscribe to the topics… From there well Google is your friend…
If it’s a 2nd pi then if you’re running Raspbian then you could get it working with NodeRED pretty easily. Once that is done I would then try the mosquitto_sub
command to see if you could re-create the functionality if you want.
The script on this page:
https://nodered.org/docs/hardware/raspberrypi
Even gives you the option of starting NodeRED as a systemD service so it launches on boot. If you’re using Arch or something non debian then things may be more tricky however.