为了账号安全,请及时绑定邮箱和手机立即绑定

MongoDB-管理员用户未经授权

MongoDB-管理员用户未经授权

翻过高山走不出你 2019-12-09 11:22:05
我正在尝试向我的MongoDB添加授权。我正在Linux上使用MongoDB 2.6.1进行所有这些操作。我的mongod.conf文件为旧的兼容格式(这是安装过程中附带的格式)。1)我按照(3)所述创建了管理员用户http://docs.mongodb.org/manual/tutorial/add-user-administrator/2)然后我通过取消注释此行来编辑mongod.confauth = true3)最后,我重新启动了mongod服务,并尝试登录:/usr/bin/mongo localhost:27017/admin -u sa -p pwd4)我可以连接,但连接时会说。MongoDB shell version: 2.6.1connecting to: localhost:27017/adminWelcome 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:~# mcMongoDB shell version: 2.6.1connecting to: localhost:27017/adminWelcome 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 adminswitched to db admin[admin] 2014-05-29 17:57:07.889 >>> show collections2014-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 testswitched to db test[test] 2014-05-29 17:57:13.466 >>> show collections2014-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用户有权执行任何操作,以便他可以随后创建其他用户并为他们提供更具体的权限。
查看完整描述

3 回答

?
梦里花落0921

TA贡献1772条经验 获得超5个赞

我也为相同的问题scratch之以鼻,在添加第一个管理员用户时,将角色设置为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' }])

有关完整的身份验证设置的参考,请参阅经过数小时的互联网研究后编写的步骤。


查看完整回答
反对 回复 2019-12-09
  • 3 回答
  • 0 关注
  • 876 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信