无法通过身份验证进入mongo,“身份验证失败"; [英] Cannot authenticate into mongo, "auth fails"

查看:595
本文介绍了无法通过身份验证进入mongo,“身份验证失败";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照以下说明为mongo创建了一个管理员用户:

I've created an admin user for mongo using these directions:

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

从mongo客户端看来,我可以进行身份​​验证:

From the mongo client it looks like I can authenticate:

> use admin
switched to db admin
> db.auth('admin','SECRETPASSWORD');
1
>

但是我无法以其他任何方式连接.例如:

But I can't connect any other way. For example:

mongo -u管理员-p密码

mongo -u admin -p SECRETPASSWORD

给出错误:

JavaScript execution failed: Error: 18 { code: 18, ok: 0.0, errmsg: "auth fails" } at src/mongo/shell/db.js:L228

我在etc/mongod.conf中有auth = true.

我想念什么?

推荐答案

身份验证在数据库级别进行管理.当您尝试使用数据库连接到系统时,mongo实际上会检查您在集合<database>.system.users中提供的凭据.因此,基本上,当您尝试连接到测试"时,它将在test.system.users中查找凭据并返回错误,因为它找不到它们(因为它们存储在admin.system.users中).拥有从所有数据库读取和写入的权利并不意味着您可以直接连接到它们.

Authentication is managed at a database level. When you try to connect to the system using a database, mongo actually checks for the credentials you provide in the collection <database>.system.users. So, basically when you are trying to connect to "test", it looks for the credentials in test.system.users and returns an error because it cannot find them (as they are stored in admin.system.users). Having the right to read and write from all db doesn't mean you can directly connect to them.

您必须首先连接到拥有凭据的数据库.试试:

You have to connect to the database holding the credentials first. Try:

mongo admin -u admin -p SECRETPASSWORD

有关更多信息,请检查此 http://docs.mongodb.org/manual /reference/privilege-documents/

For more info, check this http://docs.mongodb.org/manual/reference/privilege-documents/

这篇关于无法通过身份验证进入mongo,“身份验证失败";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆