我创建了一个管理员用户:
I created an admin user:
> db.createUser(
... {
... user: "administrator",
... pwd: "password",
... roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
... }
... )
Successfully added user: {
"user" : "administrator",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
和现在我试图使用它与输入:
and now i'm trying to use it for enter with:
ubuntu@***ip number***:/etc$ sudo mongo --port 27017 -u administrator -p password --authenticationDatabase admin
这是什么返回:
MongoDB shell version: 3.0.7
connecting to: 127.0.0.1:27017/test
2015-10-27T15:33:25.670+0000 E QUERY Error: 18 Authentication failed.
at DB._authOrThrow (src/mongo/shell/db.js:1271:32)
at (auth):6:8
at (auth):7:2 at src/mongo/shell/db.js:1271
蒙戈被安装到Amazon EC2的机器与Ubuntu。
Mongo is installed into an Amazon EC2 machine with Ubuntu.
缺什么?
在 userAdminAnyDatabase
角色允许用户授予访问权限(为自己或任何其他用户)的任何其他数据库,但是,不会自动对所有数据库授予该管理员用户读/写权限(尽管它可以在他们自己赋予它们)。您可以通过授予用户 readAnyDatabase
的附加作用,解决您的验证问题。
The userAdminAnyDatabase
role allows the user to grant access (for itself, or any other users) to any other database, however, that does not automatically grant that admin user read/write permission on all those databases (though it can bestow them upon themselves). You can resolve your authentication issue by granting the user the additional role readAnyDatabase
.
db.createUser(
{
user: "test1",
pwd: "password",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, {role:"readAnyDatabase",db:"admin"} ]
}
)
链接到MongoDB的文档:创建用户管理员