How to add new user with command line? or even to change user password with command line?

I want to add to the system the option for end-user (not admin) to create new user in a friendly way

1 Like

Hi @joelgamal, did you find a way to add the user “programmatically” via command line?

I am trying to automate the provisioning process, but I am stuck at the user account creating.

Not yet, unfortunately

@joelgamal thanks for your reply!

that’s really too bad and disappointing! This means it is really tedious to automate the installation process without user interactions or having to deal with all those files inside “/usr/share/hassio/homeassistant/.storage”.

2 Likes

I would like to know this too. I need to setup HA inside docker container for some automated tests and I do not want to access ui each time I start from zero. For me I would appreciate a way to start HA with command to create a defined user and defined Long Live Access Token.

Has someone found a solution for this? I am trying to automate the installation process so I am able to restore everything from configurations, but I couldn’t find a away to create an user.

Also want same functionality.

It occurs to me idea here is using Selenium. I know that is dirty hack, but until this feature will not be implemented I think it is viable solution.

Steps here simple:

  1. Up home assistant in docker locally
  2. Add admin user via Selenium automation (same for long live tokens)
  3. Move config to server or test what you want

There is feature request for topic? Anyone found?

Seems I found solution. Just little reverse engineered onboarding process with browser developer tools. Hope this helps for someone.

For create user you could do:

curl --location --request POST 'http://192.168.1.1:8123/api/onboarding/users' \
--header 'Content-Type: application/json' \
--data-raw '{
    "client_id": "http://192.168.1.1:8123/",
    "name": "admin",
    "username": "admin",
    "password": "12345",
    "language": "en"
}'

or same on python:

import requests
import json

url = "http://192.168.1.42:8124/api/onboarding/users"

payload = json.dumps({
  "client_id": "http://192.168.1.42:8123/",
  "name": "admin",
  "username": "admin",
  "password": "12345",
  "language": "en"
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

IP in client_id match to exposed IP. But I don’t test another options.

Next step for me is trying to create long live tokens via curl.

2 Likes

I couldn’t get this to work. Is it still working for you? Can this be done using the CLI?

@jpoeppelman1, @kwill If you or anyone else is trying to do this in a docker container, here’s the script I wrote to to do it (it takes env vars for input so it can be used in containerized jobs):

I’m actually running home assistant using a helm chart I wrote for Kubernetes, and I’m using the above script in a post install helm hook job to complete the onboarding, so the registration is disabled quickly.

NOTE: To completely disable registration and not show any errors, you still need to mount a /config/configuration.yaml file with at least ALL of the basic info listed here:

homeassistant:
  name: Home
  latitude: 32.87336
  longitude: 117.22743
  elevation: 430
  unit_system: metric
  currency: USD
  country: US
  time_zone: "America/Los_Angeles"
  external_url: "https://www.example.com"

See more info on basic config details in the home assistant docs under configuration/basics. Hope this helps :pray: