MongoDB-管理员用户未经授权 [英] MongoDB - admin user not authorized
问题描述
我正在尝试向我的MongoDB添加授权.
我正在Linux上使用MongoDB 2.6.1进行所有操作.
我的mongod.conf文件是旧的兼容格式
(这就是安装过程的方式).
I am trying to add authorization to my MongoDB.
I am doing all this on Linux with MongoDB 2.6.1.
My mongod.conf file is in the old compatibility format
(this is how it came with the installation).
1)我按照(3)所述创建了管理员用户
1) I created admin user as described here in (3)
http://docs.mongodb.org/manual/tutorial/add -user-administrator/
2)然后,我通过取消注释此行来编辑mongod.conf
2) I then edited mongod.conf by uncommenting this line
auth = true
3)最后,我重新启动了mongod服务,并尝试使用以下方式登录:
3) Finally I rebooted the mongod service and I tried to login with:
/usr/bin/mongo localhost:27017/admin -u sa -p pwd
4)我可以连接,但在连接时会显示此信息.
4) I can connect but it says this upon connect.
MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current date/time is: Thu May 29 2014 17:47:16 GMT-0400 (EDT)
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
5)现在看来,我创建的sa
用户根本没有任何权限.
5) Now it seems this sa
user I created has no permissions at all.
root@test02:~# mc
MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current date/time is: Thu May 29 2014 17:57:03 GMT-0400 (EDT)
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
[admin] 2014-05-29 17:57:03.011 >>> use admin
switched to db admin
[admin] 2014-05-29 17:57:07.889 >>> show collections
2014-05-29T17:57:10.377-0400 error: {
"$err" : "not authorized for query on admin.system.namespaces",
"code" : 13
} at src/mongo/shell/query.js:131
[admin] 2014-05-29 17:57:10.378 >>> use test
switched to db test
[test] 2014-05-29 17:57:13.466 >>> show collections
2014-05-29T17:57:15.930-0400 error: {
"$err" : "not authorized for query on test.system.namespaces",
"code" : 13
} at src/mongo/shell/query.js:131
[test] 2014-05-29 17:57:15.931 >>>
出了什么问题?我重复了整个过程3次,
我认为我按照MongoDB文档中的说明完成了所有工作.但这不起作用.
我期望这个sa
用户被授权做任何事情,以便
然后他可以创建其他用户并为他们提供更多特定的权限.
What is the problem? I repeated this whole procedure 3 times and
I think I did it all as specified in the MongoDB docs. But it doesn't work.
I was expecting this sa
user to be authorized to do anything so that
he can then create other users and give them more specific permissions.
推荐答案
我也在努力解决同一问题,在添加第一个管理员用户时,将角色设置为root后一切正常.
I was also scratching my head around the same issue, and everything worked after I set the role to be root when adding the first admin user.
use admin
db.createUser(
{
user: 'admin',
pwd: 'password',
roles: [ { role: 'root', db: 'admin' } ]
}
);
exit;
如果您已经创建了admin
用户,则可以这样更改角色:
If you have already created the admin
user, you can change the role like this:
use admin;
db.grantRolesToUser('admin', [{ role: 'root', db: 'admin' }])
有关完整的身份验证设置参考,请参阅我已经完成的步骤经过数小时的互联网研究后编译.
For a complete authentication setting reference, see the steps I've compiled after hours of research over the internet.
这篇关于MongoDB-管理员用户未经授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!