Shell command executes in commandline but not via the configuration


i have this shell command in my configuration which aims to sleep a mac:

imac_standby: 'ssh StrictHostKeyChecking=no -v -i /config/ssh/mac [email protected] "/Users/andreas/sleep"'

when i run the command in the terminal of HA it executes ok and sleeps the mac. definining it in the configuration and running it via serivces it does nothing… any ideas?

core_ssh runs in a different container as your HA does. Try running an ls or find to verify that the path is correct - it might differ.

May there be a log of your command run? As you specified -v ssh should provide further information what went wrong.

i get “Return code: 255”

and some log output of ssh?
I try to figure out if there’s something like this:

# ssh -v -i /does_not_exists
Warning: Identity file /does_not_exists not accessible: No such file or directory.

If so the path of your SSH-Key differs from core_ssh and the context of your script executing the command.

where is the log file for the ssh?

Can you share your config how you call this shell command then I can try it out and have a look.
I don’t use any shell commands so I don’t know where to find logs.

But I would look first in Configuration → System → Logs – HA Core or Supervisor.
But maybe they are in Configuration → Automations & Scenes → Automations/Scripts (what ever you use) → 3 dots menü → runs (or how ever it is translated) – and in there in the step executing the command.

i get:

Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/
Integration: Shell Command ([documentation](, [issues](
First occurred: 4:15:28 PM (3 occurrences)
Last logged: 4:16:49 PM

Error running command: `ssh StrictHostKeyChecking=no -v -i /config/ssh/mac [email protected] "/Users/andreas/sleep"`, return code: 255

NoneType: None

i define it in configuration like this:

  imac_standby: ssh StrictHostKeyChecking=no -v -i /config/ssh/mac [email protected] "/Users/andreas/sleep"

Hmm… didn’t get necessary debug logging running for the integration. According to the documentation this should provide command output in the logs.

However, the docs state the command is executed in the configuration directory. Please try this:

  imac_standby: ssh StrictHostKeyChecking=no -v -i ssh/mac [email protected] "/Users/andreas/sleep"

Note I’ve removed the /config/ from the -i switch

i tried it. same error.
i have another ssh shell communication with my router, and the definition with /config/ works.

Ahhh im blind, you need to add -o:

  imac_standby: ssh -o StrictHostKeyChecking=no -v -i /config/ssh/mac [email protected] "/Users/andreas/sleep"

As per ssh man page:

     -o option
             Can be used to give options in the format used in the configura‐
             tion file.  This is useful for specifying options for which there
             is no separate command-line flag.  For full details of the op‐
             tions listed below, and their possible values, see ssh_config(5).

Or as debug log states:

home-assistant.log.1:b'Warning: Identity file /config/ssh/mac not accessible: No such file or directory.\nOpenSSH_9.0p1, OpenSSL 1.1.1s  1 Nov 2022\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\nssh: Could not resolve hostname stricthostkeychecking=no: Name does not resolve\r\n'

Could not resolve hostname stricthostkeychecking=no: Name does not resolve → Bad :wink:

FYI: Debug logging can be activated like this:

  default: info
    homeassistant.components: debug

thanks, stupid of me, i can’t believe i missed the -o and wondering what the issue was… thanks

Always the small things :wink:

You may consider marking my post as a solution, this would help others to find it better :slight_smile:

1 Like