What user does shell_command run as?

I’m trying to make a shell_command that will use ssh to run a command against a remote server.

I’ve setup ssh keys and if I use the terminal, I can run the script with no problems, but when I run the shell_command via an automation it’s not authenticated.

My shell_command runs a script containing this:

ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no aaron@192.....

The id_rsa is available at that location and has 600 set on the permissions, but the response in the automation says:

Warning: Identity file /config/.ssh/id_rsa not accessible: No such file or directory.\nPermission denied, please try again.\r\nPermission denied, please try again.\r\naaron@192....: Permission denied (publickey,password).\r\nWarning: Identity file /config/.ssh/id_rsa not accessible: No such file or directory.\nPermission denied, please try again.\r\nPermission denied, please try again.\r\naaron@192....: Permission denied (publickey,password).

What permissions am I missing?

I’m running HAOS on a Pi.

I am far, far from expert, but my understanding is that when you log in using SSH, you are root.
When you use the shell_command, the user/owner is HomeAssistant.

1 Like

I’d imagine the shell_command runs as whatever user started homeassistant, which in almost all cases will be the homeassistant user. However, once you’ve SSHed to the remote server, it’s whoever you specified the user as, in your case aaron.

As has been eluded to, SSH key permissions can be a real pain. They need to be readable by the user accessing them AND NOBDOY ELSE!!! That chmod command should do it, just make sure that homeassistant is also the owner of the file.

One more thing, I guess you don’t want to be left with some interactive SSH terminal, since all this is running in a script. You should specify the command(s) you want to run on the remote on that SSH line. The SSH line should look something like:

ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no aaron@192..... cmd_to_execute_on_remote_server arg1 arg2....

Closing this out, the above guides work provided you copy the keys into your /config folder :person_facepalming:

Since I’m running HAOS the /config is shared into the container the SSH extension is running in, so while I was creating a symlink to the ~/.ssh folder from /config, the files weren’t accessible to HAOS.