Skip to content

Instantly share code, notes, and snippets.

@shivampip
Created November 6, 2019 16:31
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save shivampip/afa8b1dbb997c99619c593d75330e246 to your computer and use it in GitHub Desktop.
Save shivampip/afa8b1dbb997c99619c593d75330e246 to your computer and use it in GitHub Desktop.
MongoDB shell admin password reset
  • 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

@koficoud
Copy link

@hanksu-deloitte
Copy link

hanksu-deloitte commented Feb 2, 2024

what if forgot all the login users passwords for a 3-node replicaset?
how to reset root password?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment