Restoring an Admin User
You might accidentally lost access to an important admin user (or the only admin in the server) and need to restore it without using another admin user. This guide will help you in this process.
Note: To do this, you will need access to the database

Finding the database

Docker based installations

Open Mongo shell within Mongo container
Change into docker-compose directory (where your docker-compose.yml is located):
1
cd /opt/docker/Rocket.Chat
2
docker-compose run mongo bash
Copied!
or run
1
docker exec -it -u root mongo-image /bin/bash
Copied!
Make sure to replace mongo with your MongoDB container name in case you use a different one.
Login to mongo shell using :
1
mongo
Copied!
On the Mongo shell:
1
use rocketchat
Copied!
Make sure to replace rocketchat with your actual Mongo database. If you're not sure how it's called either check your docker-compose.yml file or run:
1
show dbs
Copied!

Ubuntu Snaps

Connect to MongoDB:
1
sudo rocketchat-server.mongo
Copied!
Select Rocket.Chat Database:
1
use parties
Copied!

Updating the admin password

You can either use a one time access token (that will require the user to change his password):
1
db.getCollection('users').update({username:"administrator"}, {$set: { "services":{"loginToken":{"token":"some-token-id-that-you-will-use-to-login-once"}}, "requirePasswordChange":true} })
Copied!
Then access http://{your server url}/login-token/some-token-id-that-you-will-use-to-login-once to login
or you can update the admin password to 12345
1
db.getCollection('users').update({username:"administrator"}, { $set: {"services" : { "password" : {"bcrypt" : "$2a$10$n9CM8OgInDlwpvjLKLPML.eizXIzLlRtgCh3GRLafOdR9ldAUh/KG" } } } })
Copied!
Replace administrator with the admin username in question.
Make sure to restart your application container in case the new password is not accepted yet.

Reset user role to "admin"

1
db.users.update({username:"administrator"}, {$set: {'roles' : [ "admin" ]}})
Copied!
Again, make sure to replace administrator with the admin username in question.
Last modified 1yr ago