Done!

How to create a user in Grafana using grafana-cli command line interface?

Technology
Computer Science
Engineering

Progress

6 steps completed!19.05 sec

Answer

To create a user in Grafana using the grafana-cli command line interface, you typically follow these steps:

  1. Open your terminal or command prompt.

  2. Use the following command to create a user:

    grafana-cli admin reset-admin-password <new_password>

    Replace <new_password> with the password you want to set for the new admin user. This command will reset the password for the admin user account.

  3. If you need to create a non-admin user, this functionality is not available directly through the grafana-cli command line. Instead, you will generally need to utilize the Grafana API or create the user via the Grafana web UI.

Example of Using Grafana API to Create a User

  1. Authenticate with an API Token. You will need an admin API token to perform user creation via the API. You can generate this token in the Grafana UI under Configuration -> API Keys.

  2. Use a tool like curl to create a user (replace the placeholders accordingly):

    curl -X POST http://<grafana-url>/api/admin/users \ -H "Authorization: Bearer <api_token>" \ -H "Content-Type: application/json" \ -d '{ "email": "[email protected]", "login": "newuser", "name": "New User", "password": "userpassword", "isAdmin": false }'

    Replace <grafana-url> with your Grafana instance URL, <api_token> with your admin API token, and modify the user details as needed.

Note:

  • Always ensure that you have backups and proper access control before modifying user credentials.
  • Refer to the Grafana documentation for more detailed information on user management and API usage.