Skip to content

Instantly share code, notes, and snippets.

@jperocho
Last active August 29, 2015 14:23
Show Gist options
  • Save jperocho/c8c5ddc00d4bfe7b96f1 to your computer and use it in GitHub Desktop.
Save jperocho/c8c5ddc00d4bfe7b96f1 to your computer and use it in GitHub Desktop.
Mongodb auth in ubuntu 14.04
# Besure to comment auth=true In /etc/mongod.conf.
# Start the mongod or mongos instance without the authorization
$ sudo service mongod start
# Start mongo
$ mongo
# Inside mongo run the following
# Create admin user
> use admin
> db.createUser(
{
user: "adminuser",
pwd: "1234567890",
roles: [ "root" ]
}
)
# Create database user
> use somedb
> db.createUser(
{
user: "somedb_user",
pwd: "somedb_password",
roles: ["readWrite"]
}
)
> exit
# Stop and Start mongod with auth
# Comment auth=true In /etc/mongod.conf
$ sudo service mongod stop
$ sudo service mongod start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment