MongoDB 3.0 Security Access Control-excerpt from the network

Source: Internet
Author: User
Tags mongo shell

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

Show collections

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.