Error when trying to run "ha snapshots new" over ssh

Hi folks, thanks in advance for your suggestions.

I have a backup routine that’s run from a different computer than my Home Assistant host. Currently it works fine, regularly rsync-ing off my Home Assistant Snapshots for safe keeping.

I’d like to extend it a little, by creating a Snapshot automatically too.

I can log into Home Assistant just fine using my .ssh/config below

Host homeassistant
  User root
  Port 2022
  Hostname 192.168.x.x

I can then login just fine.

$ ssh homeassistant

| |  | |                          /\           (_)   | |            | |
| |__| | ___  _ __ ___   ___     /  \   ___ ___ _ ___| |_ __ _ _ __ | |_
|  __  |/ _ \| '_ \ _ \ / _ \   / /\ \ / __/ __| / __| __/ _\ | '_ \| __|
| |  | | (_) | | | | | |  __/  / ____ \\__ \__ \ \__ \ || (_| | | | | |_
|_|  |_|\___/|_| |_| |_|\___| /_/    \_\___/___/_|___/\__\__,_|_| |_|\__|

Welcome to the Home Assistant command line.

System information ...

I can also run commands remotely just fine

$ ssh homeassistant ha

The Home Assistant CLI is a small and simple command line utility that allows
you to control and configure different aspects of Home Assistant

Usage:
  ha [command]

Available Commands:
  addons         Install, update, remove and configure Home Assistant add-ons

etc etc etc

However, it gets stuck when it gets to snapshots …

$ ssh homeassistant ha snapshots
Unexpected server response. Status code: 401
time="2021-04-09T22:12:41+01:00" level=error msg="Unexpected server response. Status code: 401"

and

$ ssh homeassistant ha snapshots new
Unexpected server response. Status code: 401
time="2021-04-09T22:13:32+01:00" level=error msg="Unexpected server response. Status code: 401"

Does anyone know a nice way of convincing Home Assistant to allow me to create the Snapshot remotely using SSH?

Many thanks as always!

Hi,
same problem here:

ssh [email protected] ‘ha core’ - works
ssh [email protected] ‘ha core restart’ - doesn’t work
Unexpected server response. Status code: 401
time=“2021-04-26T13:20:24+02:00” level=error msg=“Unexpected server response. Status code: 401”

Did you found any solution?

Thanks
Stephan

Getting the same behavior.

I had the same problem, and i finally found the solution.
The command line ha needs a token to work. To have the environment variable SUPERVISOR_TOKEN you need to call a script to set this variable.

This command is working (you should test it)

 ssh homeassistant "source /etc/profile.d/homeassistant.sh && ha core info"
8 Likes