If you happen to have lost the admin password of your grafana server and have issues logging in after many tries then you have come to the right place. Here we will go over how you can reset the grafana admin password to the default login. The default admin password for grafana is admin
This comprehensive Linux guide expects that you run the following commands as root user but if you decide to run the commands as a different user then ensure that the user has
sudo
access and that you precede each of the privileged commands withsudo
Reset Via Granafa CLI
One way to reset grafana admin password is via the grafana cli
First we need to know where grafana homepath is and where the configuration file is located. To do this we need to check the grafana process to see these information
root@codesposts:~# pa aux | grep grafana
grafana 312 0.0 0.0 2144576 21385 ? Ssl 11:22 1:04 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana cfg:default.paths.plugins=/var/lib/grafana/plugins cfg:default.paths.provisioning=/etc/grafana/provisioning
From the above we can see that grafana is currently running and the configuration file location is /etc/grafana/grafana.ini
and the homepath is expected to be located in /usr/share/grafana
Then we can now use the grafana cli command to reset the admin password for granafa
root@codesposts:~# grafana-cli admin reset-admin-password --homepath "/usr/share/grafana" --config "/etc/grafana/grafana.ini" admin
INFO[07-05|01:20:52] Connecting to DB logger=sqlstore dbtype=sqlite3
INFO[07-05|01:20:52] Starting DB migration logger=migrator
Admin password changed successfully ✔
You will see from the above output that the admin password has now been successfully reset.
Now you can go to the grafana login url and be able to log in with
username:
adminpassword:
admin
Reset Manually In Database
Another option is to reset the admin password manually from the grafana database which is by default sqlite3.
First we check the configuration file and search for the database being used
- /etc/grafana/grafana.ini
... ... #################################### Paths #################################### [paths] # Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used) ;data = /var/lib/grafana ... ... ... #################################### Database #################################### [database] # You can configure the database connection by specifying type, host, name, user and password # as separate properties or as on string using the url properties. # Either "mysql", "postgres" or "sqlite3", it's your choice ;type = sqlite3 ;host = 127.0.0.1:3306 ;name = grafana ;user = root # If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;""" ;password = # Use either URL or the previous fields to configure the database # Example: mysql://user:secret@host:port/database ;url = # For "postgres" only, either "disable", "require" or "verify-full" ;ssl_mode = disable # For "sqlite3" only, path relative to data_path setting ;path = grafana.db ... ... ...
From above we can see that the database used is sqlite3 and the database file is located at /var/lib/grafana/grafana.db
Now we connect to sqlite3 and reset the admin password manually using the sqlite3 client
root@codesposts:~# sqlite3 /var/lib/grafana/grafana.db
SQLite version 3.28.0 2019-07-04 01:12:19
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
alert dashboard_version quota
alert_notification data_source session
annotation login_attempt star
annotation_tag migration_log tag
api_key org team
dashboard org_user team_member
dashboard_acl playlist temp_user
dashboard_provisioning playlist_item test_data
dashboard_snapshot plugin_setting user
dashboard_tag preferences user_auth
sqlite> update user set password = '59acf18b94d7eb0694c61e60ce44c110c7a683ac6a8f09580d626f90f4a242000746579358d77dd9e570e83fa24faa88a8a6', salt = 'F3FAxVm33R' where login = 'admin';
sqlite> .exit
Now you can go to the grafana login url and be able to log in with
username:
adminpassword:
admin
The post How To Reset Lost Admin Password For Grafana appeared first on CODESPOSTS.COM.
Go to Source
Author: staff
Discover more from Ubuntu-Server.com
Subscribe to get the latest posts sent to your email.