Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ha commands without an interactive shell #2875

Merged
merged 1 commit into from
Apr 19, 2023

Conversation

jleeuwes
Copy link
Contributor

The ha command works if you log in through SSH and then run the command in bash, but it gives an error if invoked directly like this:

$ ssh root@hostname ha info --raw-json
Unexpected server response. Status code: 401
time="2023-02-11T14:42:33+01:00" level=error msg="Unexpected server response. Status code: 401"

This is caused by a missing SUPERVISOR_TOKEN environment variable. This variable is set in /etc/profile.d/homeassistant.sh, which is only sourced for an interactive bash session.

This PR adds a /root/.ssh/environment file containing the SUPERVISOR_TOKEN environment variable. This file is read by SSH so the environment variable is also available in a non-interactive shell. A direct invocation of ha over SSH now works:

$ ssh root@hostname ha info --raw-json
{"result": "ok", "data": {"supervisor": "REDACTED", "homeassistant": "REDACTED", "hassos": "REDACTED", "docker": "REDACTED", "hostname": "REDACTED", "operating_system": "Home Assistant OS REDACTED", "features": ["reboot", "shutdown", "services", "network", "hostname", "timedate", "os_agent", "haos", "resolved", "journal"], "machine": "generic-x86-64", "arch": "amd64", "state": "running", "supported_arch": ["amd64", "i386"], "supported": true, "channel": "stable", "logging": "info", "timezone": "Europe/REDACTED"}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants