Reset Forgotten Grafana Password: Step-by-Step Guide


How to Reset a Forgotten Grafana Password (With Root Access)

Have you locked yourself out of your Grafana dashboard? Don’t panic! If you have root access to the server hosting Grafana, regaining access is straightforward. In this guide, we’ll walk through two proven methods to reset your Grafana admin password, whether you’re using SQLite, MySQL, or PostgreSQL.


Why This Happens

Grafana stores user credentials securely in its database. If you’ve forgotten the admin password and don’t have email/SMTP configured for recovery, root access is your lifeline. Let’s dive into the solutions.


Method 1: Reset Password via grafana-cli (Fast & Recommended)

This method uses Grafana’s built-in CLI tool and works for all database types.

Step 1: SSH into Your Grafana Server

ssh root@your-grafana-server-ip

Step 2: Run the Password Reset Command

Replace new_strong_password with your desired password:

sudo grafana-cli admin reset-admin-password "new_strong_password"

Step 3: Restart Grafana (If Required)

sudo systemctl restart grafana-server

Done! Try logging in to Grafana with your new password.


Method 2: Manual Database Update (For SQLite, MySQL, PostgreSQL)

Use this if grafana-cli fails or you prefer direct database edits.

Step 1: Locate the Grafana Database

  • SQLite (default):
  /var/lib/grafana/grafana.db
  • MySQL/PostgreSQL: Check Grafana’s config file (/etc/grafana/grafana.ini).

Step 2: Backup Your Database

SQLite example:

sudo cp /var/lib/grafana/grafana.db /var/lib/grafana/grafana.db.backup

Step 3: Generate a Password Hash

Grafana uses PBKDF2-SHA256 hashing. Use this Python script to generate a hash for your new password:

import hashlib, binascii, os

password = "your_new_password"  # Replace this
salt_hex = binascii.hexlify(os.urandom(8)).decode()  # Random salt
key = hashlib.pbkdf2_hmac('sha256', password.encode(), salt_hex.encode(), 10000, 64)
hash_hex = binascii.hexlify(key).decode()
print(f"pbkdf2:sha256:10000:{salt_hex}${hash_hex}")

Save the output (e.g., pbkdf2:sha256:10000:abc123...$def456...).

Step 4: Update the Database

For SQLite:

sudo sqlite3 /var/lib/grafana/grafana.db
-- Update the admin user
UPDATE user SET password = 'your-generated-hash', salt = '' WHERE login = 'admin';
.exit

For MySQL:

UPDATE user SET password = 'your-generated-hash', salt = '' WHERE login = 'admin';

For PostgreSQL:

UPDATE "user" SET password = 'your-generated-hash', salt = '' WHERE login = 'admin';

Step 5: Restart Grafana

sudo systemctl restart grafana-server

Troubleshooting Tips

  1. Permission Issues: Ensure Grafana owns the database:
   sudo chown -R grafana:grafana /var/lib/grafana
  1. Logs Are Your Friend:
   tail -f /var/log/grafana/grafana.log
  1. Still Stuck? Temporarily disable login security in grafana.ini (not recommended for production).

Final Notes

  • Security First: Always use strong passwords and avoid reusing credentials.
  • Backups: Regularly backup your Grafana database and configurations.
  • Documentation: Refer to Grafana’s Official Docs for version-specific details.

You’re Back In! 🔑
With these steps, you’ve regained access to Grafana. Bookmark this guide for future reference, and consider setting up password recovery options (e.g., SMTP) to avoid lockouts.

Leave a Comment