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 Snaps 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 and interact with your database:
docker exec -it <mongodb-container-name> mongosh
Replace <mongodb-container-name>
with your MongoDB container name.
Now, run
use rocketchat
to access the Rocket.Chat database. Depending on your configuration, the database name may be different. You can runshow dbs
to view the available databases.Inside the Rocket.Chat database, we will need to set a temporary password for the admin user. To do this, run the following command:
db.getCollection('users').update({username:"<admin-username>"}, { $set: {"services" : { "password" : {"bcrypt" : "<hashed(bcrypt) value of the temporary password>" } } } })
Here, replace the following values in the above command:
<admin-username>
: Replace this with the admin’s username.<hashed (bcrypt) value of the temporary password>
: Replace this with the hashed bcrypt value of the password. For example, if you want to set the temporary password as 12345, enter the following bcrypt value in the command:$2b$10$9a0x6J2578m6tgJGR9SCXuY5frxmV0VlDpNfAXGPxZdNYh91GEyRW
After running the command, the entry is updated in the database.
Access your workspace. On the login page, enter your email/username and the temporary password you set (Enter the text password, not the hashed bcrypt value).
You are then redirected to change your password.
After you’ve changed your password, you can successfully access the workspace.
Additionally, if you want to set a user’s role to admin, you can run the following command in the database to do so:
db.users.update({username: "administrator"}, { $push: { roles: "admin"}})