"MongoDB" To turn on authentication permission

Source: Internet
Author: User
Tags mongodb client

1.

Mongodb.conf:

Add to

Auth=true

2.

Use Admin (3.0+ using CreateUser; <3.0 version http://www.cnblogs.com/guizi/archive/2012/11/20/2779500.html)

Db.createuser ({User: "root", pwd: "123456", roles: [{role: "Useradminanydatabase", DB: "Admin"}]})

> Db.createuser ({  User: "Root",  pwd: "123456",  roles: [{role: "useradminanydatabase", DB: " Admin " }]  }  ) successfully added User: {        " user ":" Root ",        " Roles " : [                {                        "Role": "Useradminanydatabase",                        "db": "Admin"                }        ]}

Not authorized on test to execute command-MongoDB Permissions Configuration direct Command' $eval 'Failed:not authorized on this error, you can confirm that the problem is a privilege solution: on the official website http://docs.mongodb.org/manual/reference/command/eval/#dbcmd. Eval has a description:If Authorization is enabled and you must has access to all actions on the all resourcesinchOrder to run Eval. Providing such access isn't recommended, butifYour organization requires a user to run eval, create a role this grants anyaction on Anyresource. Do not assign ThisRole to any other user. Resolution steps:1) without--The auth parameter starts the database, so you don't need an account to connect to MongoDB. 2To create a new role, such as sysadmin, you need to switch to the Admin library to do the following: [C #] Plain text view copy code>Use adminswitched to DB admin> db.createrole ({role: ' sysadmin ', Roles:[],privileges:[{resource:{anyresource:true},actions:[' Anyaction ']}]})3then, create a new user, use this role, note that the role of DB is admin, operate as follows: [C #] Plain text view copy code>Use woplusswitched to DB woplus>Db.createuser ({User:' Sa ', pwd:' Sufeinet.com ', Roles:[{role:' SysAdmin ', db: ' admin '}]) Okay, now reboot the boot database .--Auth will be able to execute normally.

3. Login

>  db.auth ("admin", "admin" authentication failed. 0> user admin2015-07-28t16:44:43.034+0800 E QUERY    syntaxerror:unexpected identifier-- This succeeds > use  adminswitched to DB admin> db.auth ("root", "123456")1
-Login Failed

> Db.auth ("Root", "111")
2015-07-28t16:52:51.352+0800 I NETWORK Socket recv () errno:10053 an established
Connection is aborted by the software in your host machine. 127.0.0.1:27017
2015-07-28t16:52:51.367+0800 I NETWORK socketexception:remote:127.0.0.1:27017
error:9001 socket exception [Recv_error] server [127.0.0.1:27017]
2015-07-28t16:52:51.367+0800 I NETWORK Dbclientcursor::init call () failed
Error:error doing query:failed
0
2015-07-28t16:52:51.371+0800 I NETWORK Trying reconnect to 127.0.0.1:27017 (127
.0.0.1) failed
2015-07-28t16:52:51.373+0800 I NETWORK Reconnect 127.0.0.1:27017 (127.0.0.1) ok

Do not know if this is the reason, after opening auth Mongovue can not connect.

Mongovue is a more useful MongoDB client, but the free version after 15 days, can not use gridfs,server monitoring and other functions.

Further research is needed on security operations

"MongoDB" To turn on authentication permission

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.