MongoDB Learning to organize the access control

Source: Internet
Author: User
Tags auth

MongoDB Learning to organize the access control

1, restricting access to specific IP addresses, only need to add the--BIND_IP parameter when starting up, the client connection should also be added--host
        /app/mongo/mongodb/bin/mongod--dbpath=/app/mongo/mongodb/data/test-- Logpath=/app/mongo/mongodb/data/test/server.log--fork--bind_ip 132.42.33.190
       /app/mongo/mongodb/bin/mongo--host 132.42.33.190

2, set the port, only need to add the--port parameter at start-up, the client connection also needs to be added--port
       /app/mongo/mongodb/bin/mongod--dbpath=/app/mongo/mongodb/data/test--logpath=/app/mongo /mongodb/data/test/server.log--fork--port 28018
       /app/mongo/mongodb/bin/mongo--port 28012

3, user authentication management
        MongoDB has an admin database by default, and the user on the admin library is larger than other libraries, that is, users of the admin library can manipulate any of the other libraries.
        
        Enabled: Login verification
           /app/mongo/mongodb/bin/mongod--dbpath=/app/mongo/mongodb /data/test--logpath=/app/mongo/mongodb/data/test/server.log--fork--auth

Note: MongoDB default has an admin database, if there is no data in Admin.system.users, login verification will not take effect

1) Create user
> Db.adduser ("Root", "111111")--New user
> Db.auth ("Root", "111111")--set user to have database connection verification

2) Set up the designated rights user,
Command format: Db.adduser (Username,password[,readonly=false])

For example: Add a read-only user User_reader to the test library, as shown in the code:
> Db.adduser ("User_reader", "Passw0rd", true)--Create a read-only user
> Show Collections--can view
System.indexes
System.users
> Db.t1.insert ({name: "Liangzhangping", age:29})--but cannot be added, deleted, and updated
Unauthorized

3) Delete the specified user, call the Db.removeuser (username) command, just pass in the user name, you can delete it, call Db.system.users.find () to see if the deletion
> Db.removeuser ("User_reader")
> Db.system.users.find ()
{"_id": ObjectId ("4fd9c4bc869208ca70bcf180"), "User": "Test", "readOnly": false, "pwd": "Ab29e5e0e27099729856ff91da2b 9112 "}


This article is from "Smile_ Youth" blog, please be sure to keep this source http://smileyouth.blog.51cto.com/7273768/1616370

MongoDB Learning to organize the access control

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.