MongoDB3.0 permission, nothing to say, Google Baidu out of all is wrong. Install the blind ditch first, simply can't say.
First, start MongoDB without using the -auth parameter:
mongodb-linux-i686-3.0. -F mongodb-linux-i686-3.0. 0/mongodb.conf |
At this point you show DBS will see only a local database, the so-called admin does not exist.
MongoDB No fried chicken invincible User root, only the user can manage user useradminanydatabase.
Open the MONGO Shell:
mongodb-linux-i686-3.0. 0/bin/mongo |
To add an administrative user:
The DB parameter in roles is required, otherwise an error will be added:error:couldn ' t add user:missing expected field "DB". In addition, there are many articles recorded is the use of Db.adduser (...) method, this method is the old version, 3.0 no longer exists, see: Http://docs.mongodb.org/manual/reference/method/js-user-management.
Switch to admin and view the user you just created:
DB. System. Users. Find () |
{ "_id ":"Admin.buru", "User ":"Buru", "DB ": "admin", "credentials": {" scram-sha-1 ": {" iterationcount ": 10000, "salt": storedkey ": serverkey ": roles ": [{" role ": " Useradminanydatabase "," db": "admin"}]} |
How do I close MongoDB? Never kill-9 pid, can kill-2 pid or db.shutdownserver ()
Use the -auth parameter below to restart MongoDB:
mongodb-linux-i686---auth-f mongodb-linux-i686-3.0.0/mongodb.conf |
Open the MONGO Shellagain:
mongodb-linux-i686-3.0. Db. Auth("Buru","12345678") #认证, return to mongodb-linux-i686-3.0. 0/bin/mongo-u Buru-12345678--authenticationdatabase admin |
At this time
Error
2015-03-17t10:15:56.011+0800EQUERYError:listcollections failed: { "OK": 0, "ErrMsg":"Not authorized the admin to execute command {listcollections:1.0}", "Code": 13error (<anonymous>) at span class= "keyword" >db._getcollectioninfoscommand (src/mongo/shell/ db.js:643:15) db.getcollectioninfos (src/mongo/ Shell/db.js:655:20) db.getcollectionnames (src/ Mongo/shell/db.js:666:17) shell/utils.js:625:12) shell/utils.js:524:36) shell/db.js:643 |
Because, the user Buru only user-managed permissions.
The user is created below, the user follows the library, and the created user is
View the user you just created.
Show Users { "Tianhe.bao", "user": "Bao", "DB": Span class= "string", "Tianhe", |
View all users of the entire MONGODB:
Use adminDb.System.users.find () {"_ID":"Admin.buru","User":"Buru","DB":"Admin","Credentials": {"Scram-sha-1": {"IterationCount":10000,"Salt":"gwvwua/dxvxgshavenlyva==","Storedkey":"L2qevteujpkcuqdekqfiwbsv4ms=","Serverkey":"M1ofnkxg2sncsfrbjbx4pxbsgvg="}},"Roles": [{"Role":"Useradminanydatabase","DB":"Admin"}]}{"_ID":"Tianhe.bao","user": "Bao", " db": "Tianhe", "credentials": { "Scram-sha-1": { "IterationCount": 10 " Salt": " //xy1v1fbqehc1gzqqzhgq==", "Storedkey": "zs/o54zzl/fdcxlqj98kdavtff0=", " Serverkey ": " Iipnyz2gk8khyk3zgz6mubt0pi4= "}}, " roles ": [{ " role ": " ReadWrite ", " db ": "Tianhe"}, { "role": "read", "db": "Tianhe2"}]} |
After creation, verify that:
Use BuruShow collections 2015-03-17t10:30:06.461+0800EQUERYError:listcollections failed: { "OK": 0, "ErrMsg":"Not authorized on Buru to execute command {listcollections:1.0}", "Code": 13}error (<anonymous>) at Db._getcollectioninfoscommand (src/mongo/shell/db.js:643:15) db.getcollectioninfos (src/mongo/shell/db.js:655:20" db.getcollectionnames (src/mongo/shell/db.js:666:17" shell/utils.js:625:12) shell/utils.js : 524:36) shell/ db.js:643 |
Obviously do not have the authority, first Auth:
Db. auth("Bao",systemWahaha |
Complete!
Reference: Mongo Shell:http://docs.mongodb.org/v2.2/tutorial/getting-started-with-the-mongo-shell Enable Access control:http ://docs.mongodb.org/manual/tutorial/enable-authentication Add A User to a database:http://docs.mongodb.org/manual/ Tutorial/add-user-to-database User Methods:http://docs.mongodb.org/manual/reference/method/js-user-management Role methods:http://docs.mongodb.org/manual/reference/method/js-role-management
MongoDB 3.0 Security Access Control-excerpt from the network