MongoDB - 管理员用户未授权

标签 mongodb admin

我正在尝试向我的 MongoDB 添加授权。
我正在使用 MongoDB 2.6.1 在 Linux 上执行所有这些操作。
我的 mongod.conf 文件是旧的兼容格式
(这就是它的安装方式)。

1) 我按照 (3) 中的描述创建了管理员用户

http://docs.mongodb.org/manual/tutorial/add-user-administrator/

2) 然后我通过取消注释这一行来编辑 mongod.conf

auth = true

3) 最后我重新启动了 mongod 服务并尝试使用以下命令登录:

/usr/bin/mongo localhost:27017/admin -u sa -p pwd

4) 我可以连接,但连接时会显示。

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 用户根本没有权限。

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 用户被授权做任何事情,以便
然后他可以创建其他用户并赋予他们更具体的权限。

最佳答案

我也在为同样的问题摸不着头脑,在添加第一个管理员用户时将角色设置为 root 后一切正常。

use admin
db.createUser(
  {
    user: 'admin',
    pwd: 'password',
    roles: [ { role: 'root', db: 'admin' } ]
  }
);
exit;

如果您已经创建了 admin 用户,您可以像这样更改角色:

use admin;
db.grantRolesToUser('admin', [{ role: 'root', db: 'admin' }])

有关完整的身份验证设置引用,请参阅 steps我在互联网上进行了数小时的研究后编译。

关于MongoDB - 管理员用户未授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23943651/

相关文章:

python - MongoDB node.js驱动安装需要Python吗?

mongodb - Mongos 内存使用量不断增加

ruby-on-rails - 处理我想在所有 Rails 环境中使用的大多数静态数据的最佳实践是什么?

php - url 重定向到根文件夹后的 Laravel 斜线

grails - 易于扩展 mongodb 与 mysql

node.js - 如何访问 mongoose 中的字段名称 $aggregate->$lookup-> pipeline->$match

redirect - 向使用 "Start-Process powershell -Verb runas"打开的 powershell 发送命令

powershell - 如何从 PsList 传输 'Elapsed Time'(或其他输出)

php - wordpress管理面板,如何防止用户删除类别?

javascript - 无法运行本地主机:3000 on meanstack MEANIO, https ://github. com/linnovate/mean