Bash script from Button Card does not work


I am new to HA.

System information

Version 			       core-2023.5.0
Installation Type 		Home Assistant Supervised
Development 			false
Supervisor 			true
Docker 				true
User 				root
Virtual Environment 		false
Python Version 			3.10.11
Operating System Family 	Linux
Operating System Version 	5.10.0-22-amd64
CPU Architecture 		x86_64
Configuration Directory 	/config

Home Assistant Cloud
Logged In 			false
Reach Certificate Server 	ok
Reach Authentication Server 	ok
Reach Home Assistant Cloud 	ok

Home Assistant Supervisor
Host Operating System 		Debian GNU/Linux 11 (bullseye)
Update Channel 			stable
Supervisor Version 		supervisor-2023.04.1
Agent Version 			1.5.1
Docker Version 			23.0.5
Disk Total 			144.7 GB
Disk Used 			8.9 GB
Healthy 			true
Supported 			true
Supervisor API 			ok
Version API 			ok
Installed Add-ons 		Studio Code Server (5.5.7)

I have a few bash scripts that I would like to initiate from HA. I started with a simple test.


# Loads default set of integrations. Do not remove.

# Load frontend themes from the themes folder
  themes: !include_dir_merge_named themes

# Text to speech
  - platform: google_translate

  script_117_001_test_1: touch /tmp/zt1.txt

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

This is my Button Card Configuration:

show_name: true
show_icon: true
type: button
  action: call-service
  service: shell_command.script_117_001_test_1
  target: {}
show_state: false
name: 117_001_test_1
  action: none
icon_height: 50px

When I click on this button, it flashes but nothing happens… There is no /tmp/zt1.txt file.
What am I doing wrong?

That command is running inside the HA container, where /tmp is also inside the container. If you’re then looking for that file via ssh, which is yet another container, then you won’t find it. That same mindset applies to shell_command, command_line sensors, etc. - they run in the HA container with a completely different filesystem and only specific external directories are mounted from the host. If you want to check the side effect of your shell_command that way, use touch /config/zt1.txt and look for it in the /config directory.

Thanks Rob.

I did change the shell_command to … touch /config/zt1.txt and found zt1.txt in the /config directory.

Also, I installed the “Terminal & SSH” add-on.

This allowed me to access core-ssh via ssh [email protected]

Where I can cd /config and find the same zt1.txt

Moving on with the same issue …

As root on, I did:
ssh-keygen -t rsa
ssh-copy-id [email protected]
with the password for user1 on

Now, as root on, I can
ssh [email protected]
without the password for user1 on

Still logged in as root on, I can
ssh -l user1 “touch /tmp/zt1.txt”
without the password for user1 on
and I can see file /tmp/zt1.txt created on by user1

On HA, I made the same change
script_117_001_test_1: ssh -l user1 “touch /tmp/zt2.txt”

Restarted HA, and clicked on the Button Card but there is no /tmp/zt2.txt created on

The /var/log/auth.log on shows
sshd[1074]: Connection closed by port 52538 [preauth]
where is the debian system running HA

Is my “shell_command: ssh -l …” script running in another container?

Still trying to get this Button Card to now execute a bash script … now via ssh.

Is my “shell_command: ssh -l …” script running in another container?

It’s running in the HA container, as I said. See this for how to properly use SSH:

Thanks Rob.

That helped.