How to create a database with a user name and password for MongoDB

Source: Internet
Author: User
Tags md5 hash

MongoDB Default user authentication is off.
Modify the/etc/mongod.conf file. MongoDB by default, any client can connect to port 27017 without authentication, which by default does not have an administrator account. By modifying this profile, you can change the permission authentication to login.
MongoDB If you want to create a user for a database, you need to enter the database first, and then use the AddUser command. Here you can also set the user to read-only (Db.adduser ("Jack", "Jack", true), and the third parameter indicates whether to "read-only user" at the time).

To use a super administrator, you need to connect to the Admin database and log in to the Administrator account, and then connect to other databases to exercise administrator privileges.

User Information preservation and certification process

Similar to MySQL, the system user information is saved in the Mysql.user table. MongoDB also stores the username and pwd of the system user in the Admin.system.users collection. where PWD = MD5 (username + ": MONGO:" + Real_password). There is nothing wrong with this in itself. Username and: MONGO: equivalent to adding a salt value to the original password, even if the attacker obtains the stored MD5 hash in the database, it is impossible to easily isolate the original password from the Rainbow table.

Rights Management Common commands

1. #进入数据库admin

Use admin

2. #增加或修改用户密码

Db.adduser (' name ', ' pwd ')

3. #查看用户列表

Db.system.users.find ()

4. #用户认证

Db.auth (' name ', ' pwd ')
This one returns 1 certification successful, only the successful authentication to the database operation

5. #删除用户

Db.removeuser (' name ')

6. #查看所有用户

Show Users

7. #查看所有数据库

Show DBS

8. #查看所有的collection

Show collections

9. #查看各collection的状态

Db.printcollectionstats ()

Ten. #查看主从复制状态

Db.printreplicationinfo ()

How to create a database with a user name and password for MongoDB

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.