3

I have tried setting up username / password .But none of the methods seems to work.

1. In mongod.conf ----> remove **#auth=true** to **auth =true**


2.Started the mongod server --> sudo service mongodb restart


3. Created the user in --> use admin -->db.createUSer()
Followed these procedure still not able to figure out how it works its not working.

mongod --auth

But then I try to connect its opening with out any username password error.

I have checked many documentations and answers but was still not able to figure out.

1 Answer 1

3

Create an admin to create users:

> use admin
> ( rs.initiate() )
> db.createUser({user:"siteUserAdmin",pwd:"password",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})

Login as userAdmin:

$ mongo -u siteUserAdmin -p password --authenticationDatabase admin

Create an admin for the cluster:

> use admin
> db.createUser({user:"replSetManager",pwd:"password",roles:[{role:"clusterManager",db:"admin"}]})
> db.auth(replSetManager,password)
> rs.status()  -> ok

Create a user that can access all databases but not admin:

> use admin
> var w = { user:"will", roles:["readWriteAnyDatabase"], pwd:"abc"}
> db.createUser(w)

Create a user only for the test database:

> use test
> var a = { user:"joe", pwd:"asdf", roles:["readWrite"]}
> db.createUser(a)

Many roles can be combined and you can create super admins. Information on all the built-in-roles: http://docs.mongodb.org/manual/reference/built-in-roles/

(You can build your own roles also if needed: http://docs.mongodb.org/manual/tutorial/manage-users-and-roles/#create-user-defined-role)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.