In managing any digital platform, there may be instances where access to an admin user is lost and needs to be restored.
This document guides you through the process of restoring an admin user in Rocket.Chat by accessing the database. This method does not require another admin user.
Accessing the database
Depending on how the Rocket.Chat server was installed, you can access the MongoDB database in various ways. The Mongo shell within the Mongo container can be accessed for Docker deployments, and for Ubuntu Snap installations, MongoDB can be connected directly.
In this guide, we will follow the steps for Docker deployments.
Run the following command to access the MongoDB shell:
docker exec -it <mongodb-container-name> mongoshReplace <mongodb-container-name> with your MongoDB container name.
Next, switch to the Rocket.Chat database:
use rocketchatDepending on your configuration, the database name may differ. You can run:
show dbsto view available databases.
Resetting the admin password
Inside the Rocket.Chat database, set a temporary password for the admin user using the following command:
db.users.updateOne(
{ username: "<admin-username>" },
{ $set: { "services.password.bcrypt": "<bcrypt-hash>" } }
)Replace the following values:
<admin-username>: The username of the admin account.<bcrypt-hash>: A valid bcrypt hash of your temporary password.
Do not paste a plain text password here. You must generate a bcrypt hash first.
Generating a valid Bcrypt Hash
You can generate a bcrypt hash using Node.js or Python.
Option 1: Using Node.js
Run this in your terminal:
node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 10))" "TempPass123!"Replace TempPass123! with your desired temporary password.
Option 2: Using Python
python3 - <<'PY'
import bcrypt
pw = b"TempPass123!"
print(bcrypt.hashpw(pw, bcrypt.gensalt(rounds=10)).decode())
PYCopy the generated hash and paste it into the updateOne command.
After running the MongoDB command, you should see output similar to:
{ acknowledged: true, matchedCount: 1, modifiedCount: 1 }This confirms the password was updated.
Logging in
Go to your Rocket.Chat login page.
Enter the admin username/email.
Use the plain text temporary password (e.g.,
TempPass123!).You will be prompted to change your password.
Set a new secure password.
You should now have full access again.
Setting a User as Admin (optional)
If you also need to grant admin privileges, run:
db.users.updateOne(
{ username: "administrator" },
{ $addToSet: { roles: "admin" } }
)Using $addToSet ensures the admin role is not duplicated if it already exists.