Skip to content

Instantly share code, notes, and snippets.

@willywg
Forked from tamoyal/gist:10441108
Created February 5, 2016 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willywg/31f38a24afed0199eaf6 to your computer and use it in GitHub Desktop.
Save willywg/31f38a24afed0199eaf6 to your computer and use it in GitHub Desktop.
Create super user and database user in Mongo 2.6
# Create your superuser
$ mongo
> use admin
> db.createUser({user:"someadmin",pwd:"secret", roles:[{role:"root",db:"admin"}]})
> exit
# Alias for convenience (optional and at your own risk)
$ echo 'alias mongo="mongo --port 27017 -u someadmin -p secret --authenticationDatabase admin"' >> ~/.bash_profile
$ source ~/.bash_profile
# Add user to your DB
$ mongo
> use some_db
> db.createUser(
{
user: "mongouser",
pwd: "someothersecret",
roles: ["readWrite"]
}
)
# If you get locked out, start over
sudo service mongod stop
sudo mv /data/admin.* . # for backup
sudo service mongod start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment