MongoDB Security Check

Source: Internet
Author: User
Tags auth

  First, the importance of MongoDB security check

The database in each MongoDB instance can have many users. If the security check is not enabled and the user is restricted, each user who enters the database can read, write, or even write to the database data. Such scenes in the actual application is very dangerous, easy to lead to data loss, accidental deletion and other accidents, so the database service to open security check, it is necessary.

Second,MongoDB How to turn on security check

Once MongoDB has turned on security, it must be a database authentication user to be able to read, write, or read data. Be sure to have at least one administrator account before conducting a security check. Because only administrators can read and write to any database, execute specific administrative commands, such as adding specific users to a database, restricting read and write permissions, and so on.

For example, the admin database has been added Super Administrator root, password is 1234, convenient after the database to open security checks, using the user login after the database can be managed, add the user's syntax for

    Db.adduser ("username", "password", whether read-only true|false)

Then two users were added to the Kaiye database, with the syntax

Db.adduser ("haha", "123"): Haha user has read and write access to the Kaiye database

Db.adduser ("hehe", "123", true): hehe user has only read access to the Kaiye database

After restarting the server and adding--auth after the Open Server command, the MongoDB security check is initiated.

Mongod--dbpath=c:\\mymongodb--port 27017 --auth

    

    After the security check is turned on at the server, the haha and hehe users are logged in, and the data reads and writes, and the exception is reported without permission at show collections.

    

At this time need to use the database user authentication login, Syntax: Db.auth ("User name", "password"), login just added hehe user (added read-only permission), found that the data can only be retrieved query, but not the data insert operation, This is because the third value of the AddUser () function was set to True when the hehe user was added to the Kaiye database just now, that is, the user has read-only permissions, so the write operation cannot be performed.

    

Switching users, that is, haha users who have read and write access at the same time, will find that both the find operation and the insert operation are possible.

    

    

    

MongoDB Security Check

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.