Home Assistant Community Add-on: SSH & Web Terminal

I want to run a automation in this add-on but for some reason sent commands eare not working.

This is mi automation:

alias: Test automation ssh addon
description: test
# any valid trigger, I will be executing it manually for test.
trigger:
  - platform: template
    value_template: '{{ states("sensor.time") == "03:00" }}'
condition: []
action:
  - service: hassio.addon_stdin
    data:
      addon: core_ssh
      input: sh /config/command-scripts/test_script.sh
mode: single

and inside test_script.sh:

#!/bin/bash

# change directory
cd config

# print data to file
ls -a > test1.txt

# close
exit

But it is not working and I donā€™t see any error in my logs.
Iā€™m running home assistant core.

Can someone help me with this?

this is all that is needed:

authorized_keys: []
apks: []
password: password
server:
  tcp_forwarding: false

and configure the port:


or any other port you wantā€¦ pick save and youā€™re good to go?

different versions though?

Hi, Marius!
I tried your options, tried others - does not work.
Finally, I just removed whole HassOS - tired of trying to make it at least as working as my HA Docker.
Some differences are critical (like absence of normal SSH), some are less critical (like glitches with HACS); also there are some small differences which make HassOS not appropriate for meā€¦ OK, may be I just cannot deal with HassOS. So, I went back to HA Docker and I am quite happy with it))).

I was ussing the wrong add-on: core instead community.
Sorry

Hi,

When I am on the web UI, how do I pass certain Ctrl-X commands to the shell rather than to my browser? Some work, but, for example, Ctrl-A does not (nor Ctrl-D, I donā€™t think).

Thanks,

James

Hey

New user

Im getting 502: Bad Gateway

Iā€™m hosting on a pi 3 b

I am trying as well to have it working. I am using the latest version of the community add-on, using Hassos 6.1 on a NUC but I have no error message and nothing happens when I submit the service: no error even if I am in debug mode in the add-onā€¦

Have you configured something to make it work in configuration.yaml or in the add-on ? I have no clue whatā€™s wrongā€¦

are you using the correct addon?
Tha was my mistake.

And this is my config for it:
imagen

ssh:
  username: hassio
  password: ''
  authorized_keys: []
  sftp: false
  compatibility_mode: false
  allow_agent_forwarding: false
  allow_remote_port_forwarding: false
  allow_tcp_forwarding: false
zsh: true
share_sessions: false
packages: []
init_commands: []

This is my script

alias: Subir configuraciĆ³n a Github
icon: mdi:upload
sequence:
  - service: hassio.addon_start
    data:
      addon: a0d7b954_ssh
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: hassio.addon_stdin
    data:
      addon: a0d7b954_ssh
      input: >-
        sh /config/command-scripts/git_push_config.sh "{{
        states("input_text.github_commit_message") }}"
  - service: input_text.set_value
    target:
      entity_id: input_text.github_commit_message
    data:
      value: ''
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: hassio.addon_stop
    data:
      addon: a0d7b954_ssh
mode: single

And finally sh script

#!/bin/bash

# get input message
input_msg="$*"

# change directory
cd ~/config

# Get HA version
ha_version=$(cat .HA_VERSION)

# if input message is empty, use default message
message=${input_msg:-"Udate config on `date +'%d-%m-%Y'` - version: $ha_version"}

# Add all files to the repository with respect to .gitignore rules
git add .

# Commit changes with message with current date stamp
git commit -m "$message"

# Uncomment next line first time
# git config core.sshCommand "ssh -i ~/.ssh/id_rsa -F /dev/null"

# Push changes towards GitHub
git push

exit

Well I have the same configuration and not working for meā€¦ strangeā€¦ and no error message to be able to track what is not working: I checked home-assistant.log, SSH log and system logā€¦ All are OKā€¦but it seems the stdin command is going nowhereā€¦ Thank you for your help.

Did you try to execute it first in the console?

And if you script use something like the ssh agent for a password, I couldnā€™t make it work.

What are you trying to do?

Well my configuration force me to have a password or a key for SSH (I am using version 9.0.0 of SSH and Web Terminal). So I put a password. I tried from the console but same issue, no error messageā€¦

I am trying to submit a shell script (I tried yours in your first example) but even this one is not working for me.

Here is the info shared when SSH is starting:


Add-on version: 9.0.0
You are running the latest version of this add-on.
System: Home Assistant OS 6.1 (amd64 / generic-x86-64)
Home Assistant Core: 2021.7.4
Home Assistant Supervisor: 2021.06.8

Here is the log after the info I shared above

[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] docker.sh: executing... 
[cont-init.d] docker.sh: exited 0.
[cont-init.d] mosquitto.sh: executing... 
[cont-init.d] mosquitto.sh: exited 0.
[cont-init.d] mysql.sh: executing... 
[cont-init.d] mysql.sh: exited 0.
[cont-init.d] ssh.sh: executing... 
[13:58:10] INFO: Password is NOT in the Have I Been Pwned database! Nice!
[13:58:10] WARNING: 
[13:58:10] WARNING: Logging in with a SSH password is security wise, a bad idea!
[13:58:10] WARNING: Please, consider using a public/private key pair.
[13:58:10] WARNING: What is this? https://kb.iu.edu/d/aews
[13:58:10] WARNING: 
[cont-init.d] ssh.sh: exited 0.
[cont-init.d] user.sh: executing... 
[13:58:11] NOTICE: Session sharing has been disabled!
[cont-init.d] user.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[13:58:11] INFO: Starting the Home Assistant STDIN service...
[13:58:11] INFO: Starting the ttyd daemon...
[13:58:11] INFO: Starting the SSH daemon...
Server listening on 0.0.0.0 port 22.

Server listening on :: port 22.

Iā€™m not talking about addon pasword. Iā€™m talking about autenticate with ssh inside addon console or script. At begining I used a ssh key protected with pasword. Finally I used ssh key without pasword because I never was able to make it work.

When I searched info about that I find that the problem is that addon is executed in different container and donā€™t have access to same files or samething like that.

Iā€™m quite sure that the problem is related to ssh agent. Why you donā€™t try without password to check if it works.

Here is what I try to achieve:

Write an automation using hassio.addon_stdin to run a shell script, so I tried the command (via the services menu in HA)

- service: hassio.addon_stdin
  data:
     addon: a0d7b954_ssh
     input: /config/myscript

I have no error message when I run the script from the terminal in HA but I am sure the script is not executed (and I have no error message) when I run it with hassio.addon_stdin (as described above) as this script should create a file, and the file is not created. I donā€™t understand whyā€¦

I presume that the add_on ā€œSSH and Web Terminalā€ is creating the environment to submit command with hassio.addon_stdin without having to configure anything within HA environment. Right ?

The add-on ā€œSSH and Web Terminalā€ is starting without error or warning.
My config for the add-on "SSH and Web Terminal (V 9.0.0) is:

 ssh:
  username: hassio
  password: ''
  authorized_keys:
    - >-
      ssh-rsa
      AAAAB3Nza...==
  sftp: false
  compatibility_mode: false
  allow_agent_forwarding: false
  allow_remote_port_forwarding: false
  allow_tcp_forwarding: false
zsh: true
share_sessions: false
packages: []
init_commands: []

I didnā€™t make any other configuration. Installed addon with default config and run.

try addin sh (if script is a sh) before the file path

- service: hassio.addon_stdin
  data:
     addon: a0d7b954_ssh
     input: sh /config/myscript.sh

The other question is, if you run your script typing in the console does it runs ok?

I got it to work ! I did two things : uninstall/install SSH add-on and than modified the command passed to the service, like this:

service: hassio.addon_stdin
data:
  addon: a0d7b954_ssh
  input: "/bin/bash /config/myscript.sh"

I do not know which one fixed it, but now it is perfectly working ! Thank you for your help !!!

nice to know its working!

I think that the one that fixes it is the command changed. It should work too with ā€œshā€ .

Hi all,
I am running my HA from an Odroid N2+. I installed the SSH & Web Terminal to change the tripping Temperature to run a cooling fan (fed from the Odroid board). The fan should go on when reaching 65 degrees Celcius (fudging way too high!) so I am trying to lower the tripping temperature via SSH. In SSH (from within HA), I type the following command echo 20000 > /sys/devices/virtual/thermal/thermal_zone0/trip_point_4_temp however, I get the response ā€˜zsh: read-only file system: echo 20000 > /sys/devices/virtual/thermal/thermal_zone0/trip_point_4_tempā€™

I disabled the zsh to go back to bash, but the same message is shown. Any suggestions?!

Thank you!

if HAOS then you are in the wrong containerā€¦

thanks for the reply, I am pretty new to HAOS so I quite donā€™t get what you are saying. Does it mean that Cooling Fan properties cannot be modified?

Does that file exist if you do a cat /sys/devices etcā€¦
When you ssh from the addin you are getting a console/ssh session in the ssh container and you probably need to do it on the host itselfā€¦ if you are using HAOS you probably canā€™t do that