- open mongod.conf
cd /etc/mongod.conf
- Comment security
#security:
# authroization: "enabled"
- Restart mongodb
sudo service mongod stop
sudo service mongod start
- Run mongo
mongo
- Run these cmds
use admin
db.createUser({user:"admin",pwd:"password",roles:[{role:"root",db:"admin"}]});
-
Enable auth again what you had commented in /etc/mongod.conf file (remove comments)
-
Restart mongod service again
-
DONE
Hi hanksu-deloitte:
I think that the steps to reset the root password for a 3-node MongoDB replica set can be done as follows:
Stop the MongoDB service on all nodes:
sudo service mongod stop
Start one of the MongoDB instances without authentication:
mongod --dbpath /var/lib/mongodb --port 27017 --bind_ip localhost --replSet yourReplicaSetName --fork --logpath /var/log/mongodb/mongod.log
Connect to the started MongoDB instance using mongosh:
mongosh --port 27017
In the MongoDB shell, execute the following commands to reset the root user's password:
Shut down the MongoDB instance:
mongosh admin --eval "db.shutdownServer()"
Restore the security settings in /etc/mongod.conf:
Restart the MongoDB service on all nodes:
sudo service mongod start
Check the replica set status to ensure all nodes are running correctly:
mongosh --username root --password newpassword --authenticationDatabase admin --eval "rs.status()"
By following these steps, you should be able to successfully reset the root password for your 3-node MongoDB replica set. Make sure to understand the potential risks and impacts of performing these operations.