Skip to content

Instantly share code, notes, and snippets.

@light9
Forked from shivampip/mongodb_pass_reset.md
Created August 1, 2022 09:47
Show Gist options
  • Save light9/23a6d01e8e0494dfe991c1a8f3852561 to your computer and use it in GitHub Desktop.
Save light9/23a6d01e8e0494dfe991c1a8f3852561 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

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