Server admin is deleted or missing from Grafana account

This problem occurred when super admin (server admin) credentials got deleted when that user left organisation.
Best practice is that super admin privileges has to be transfer to someone with admin role.
in such cases use below command

grafana-cli --homepath “/usr/share/grafana” admin reset-admin-password

if this not works or it may give error that could not read user from database so in that situation only we have to run below command. Make sure you have stopped Grafana server by

systemctl stop grafana-server

then with root or sudo access use
sqlite3 /var/lib/grafana/grafana.db

then paste below command
INSERT INTO user (id, version, login, email, name, org_id, is_admin, created, updated) VALUES(1, 0, ‘admin’, ‘admin@localhost’, ‘Admin’, 1, 1, datetime(‘now’), datetime(‘now’));

then press ctrl + d to exit from sqlite3

then try to reset password by
grafana-cli --homepath “/usr/share/grafana” admin reset-admin-password

it will show Admin password changed successfully :heavy_check_mark:

then restart grafana server by
systemctl restart grafana-server

Now check on your browser ‘community.grafana.com’
use user as admin & password you set

make sure that while doing database changes grafana server has to be stopped else it may not reflect changes in some cases

2 Likes

Hi @ni33wagh,

I have asked this question from the Engineering team and it seems that this is not possible as Grafana does not have a way to simply copy all of one user’s permissions over to someone else.

What you are doing seems to be the right method if in case the server administrator employee left the company/organization.

Also, If you are using RBAC and have some other manual role assignments, then should also think about assigning those to that other person (or write a script to do that).

I hope this helps.

@usman.ahmad Its specifically for server admin missing due to absence of server admin we won’t be able to add or remove other users also we can’t attach role to different servers
so server admin is the default & main component to manage grafana.
whatever I have mentioned in earlier post worked for me & now I am able to manage my grafana where I was unable in past in absence of server admin

I get “unable to upen database file” :frowning:

Hi @faecon ,

You need to install SQLite program on your machine which will give you a command line interface to interact with the database file.

Alternatively, you can install a 3rd party software e.g. https://sqlitestudio.pl/ to edit the database

1 Like

When I use this I get the sqlite> so I think I’m in it , no ?

1 Like

Also read the docu

Create a team

Create the Marketing and Engineering teams.

  1. In the sidebar, hover your mouse over the Configuration (gear) icon and then click Teams.
  2. Click New team.
  3. In Name, enter the name of the team: either Marketing or Engineering. You do not need to enter an email.
  4. Click Create.
  5. Click on the Teams link at the top of the page to return to teams page and create the second team.

Add a user to a team

Repeat these steps for each user to assign them to their team. Refer to the table above for team assignments.

  1. Click the team name Marketing or Engineering to add members to that team.
  2. Click Add member.
  3. In the Add team member box, click the drop-down arrow to choose the user you want to add to the team .
  4. Click Add to team.

When you’re done, you’ll have two teams with two users assigned to each.

sqlite3 /var/lib/grafana/grafana.db
SQLite version 3.10.2 2016-01-20 15:27:19
Enter ".help" for usage hints.
sqlite> INSERT INTO user (id, version, login, email, name, org_id, is_admin, cre                                                                                                                                                             ated, updated) VALUES(1, 0, ‘admin’, ‘admin@localhost’, ‘Admin’, 1, 1, datetime(                                                                                                                                                             ‘now’), datetime(‘now’));
Error: unable to open database "/var/lib/grafana/grafana.db": unable to open dat                                                                                                                                                             abase file

Create users and teams | Grafana Labs.

Your approach while good to solce the issue quickly, in the long term it is not a sustainable and safe approach. What if you blow away the grafana.db by mistake then you will lose everything.

Implement teams and add users to teams and grant permissiojln to teams rather than individual users.

Actually this is security best practice across many technologies

ah ok, thanks. But I can’t acces any of my Grafana accounts. not the admin, not my normal “Joachim” account. I get invalid password…

I would not mess with the database unless you really know what you are doing and you dont care if you blow up the db.

Try to change the password of an existing user and make them admin. Or create an admin user using grafana api.

Again for that you need to be intimately familiar with the documentation

Once you read the doco and try it out and you are stuck post back here with the issues.

this is all to difficult for me. I want to solve 1 thing, an a next problem arrives. I don’t know what and where to start. It stops here for me. I just want to make graphs and have no nowledge of programming and programming language. its just to difficult for me.

i found this code, but I don’t know how to use it…

import requests
import json

grafana_url = "ip172-18-0-23-c8vdq1g9jotg00duhte0-3000.direct.labs.play-with-docker.com"
username = "admin"
password = "admin"

base_url = "http://{}:{}@{}".format(username, password, grafana_url)

data = {
 "password":"newPassword" }


resp = requests.put(base_url + "/api/admin/users/2/password", json=data, verify=False)
data = resp.json()
data
1 Like

It should not be too difficult, but we can help guide you

how do I use this code then ?

@faecon by running that command you will be in the sqlite database similar like mysql database.
once you entered then only you can run that command.
If you are still facing issues then we can connect to solve the issue.
Kindly let me know your availability on ni33wagh@gmail.com
also try below solution

This problem occurred when super admin credentials got deleted when that user left organization.
Best practice is that super admin previlages has to be transfer to someone with admin role.
in such cases use below command

grafana-cli --homepath “/usr/share/grafana” admin reset-admin-password

if this not works or it may give error that could not read user from database so in that situation only we have to run below command. Make sure you have stopped Grafana server by

systemctl stop grafana-server

then with root or sudo access use
sqlite3 /var/lib/grafana/grafana.db

then paste below command
INSERT INTO user (id, version, login, email, name, org_id, is_admin, created, updated) VALUES(1, 0, ‘admin’, ‘admin@localhost’, ‘Admin’, 1, 1, datetime(‘now’), datetime(‘now’));

then press ctrl + d to exit from sqlite3

then try to reset password by
grafana-cli --homepath “/usr/share/grafana” admin reset-admin-password

it will show Admin password changed successfully :heavy_check_mark:

then restart grafana server by
systemctl restart grafana-server

Now check on your browser ‘community.grafana.com
use user as admin & password you set

make sure that while doing database changes grafana server has to be stopped else it may not reflect changes in some cases

1 Like

@faecon I hope you have access of that grafana server cli
also check whether your database is present at /var/lib/grafana
There could be chance that your database may removed due to some reason.
still you are unable to solve the same then we can connect to solve this
ni33wagh@gmail.com
Share your availability

Hi @faecon,

Also, not to make things too complicated (as I feel you only need to reset the password).

If you do have access to the server via SSH where the grafana-service is running then you can follow this documentation guide which can reset the master admin password and then from that you can log in as admin and reset any user password easily:

Ok thanks. I’ll try that