What's the procedure to set up username/password on mongodb? I have tried setting up username / password .But none of the methods seems to work.

1. In mongod.conf ----&gt; remove **#auth=true** to **auth =true**


2.Started the mongod server --&gt; sudo service mongodb restart


3. Created the user in --&gt; use admin --&gt;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.
Create an admin to create users:

&gt; use admin
&gt; ( rs.initiate() )
&gt; 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:

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


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

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


Create a user only for the test database:

&gt; use test
&gt; var a = { user:"joe", pwd:"asdf", roles:["readWrite"]}
&gt; 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)