MongoDB 客户端访问控制:SCRAM-SHA-1 身份验证失败,存储密钥不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37811036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:46:42  来源:igfitidea点击:

MongoDB Client Access Control: SCRAM-SHA-1 authentication failed, storedKey mismatch

mongodb

提问by rustyx

I'm trying to activate user authorization on my local Mongo installation, but authentication keeps on failing. What can be the problem? Am I missing something?

我正在尝试在本地 Mongo 安装上激活用户授权,但身份验证一直失败。可能是什么问题?我错过了什么吗?

I followed the steps outlined in "Installing on Windows" and "Enable Client Access Control":

我遵循了“在 Windows 上安装”和“启用客户端访问控制”中概述的步骤:

1) Added a user

1) 添加了一个用户

>mongo admin
MongoDB shell version: 3.2.7
connecting to: admin
> db.createUser({createUser:"admin",pwd:"admin",roles:["root"]})
Successfully added user: { "createUser" : "admin", "roles" : [ "root" ] }
>

2) Enabled Client Access Control in mongod.cfg:

2) 启用客户端访问控制mongod.cfg

systemLog:
    destination: file
    path: c:\data\log\mongod.log
storage:
    dbPath: c:\data\db
security:
    authorization: enabled

3) Restarted mongod

3) 重新启动 mongod

4) Now logging in with the "right" credentials (the ones I just specified) always fails:

4)现在使用“正确”凭据(我刚刚指定的凭据)登录总是失败:

>mongo admin -u admin -p admin
MongoDB shell version: 3.2.7
connecting to: admin
2016-06-14T12:25:02.376+0200 E QUERY    [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1441:20
@(auth):6:1
@(auth):1:2

exception: login failed

The error in the logfile is: SCRAM-SHA-1 authentication failed for admin on admin from client 127.0.0.1 ; AuthenticationFailed: SCRAM-SHA-1 authentication failed, storedKey mismatch

日志文件中的错误是: SCRAM-SHA-1 authentication failed for admin on admin from client 127.0.0.1 ; AuthenticationFailed: SCRAM-SHA-1 authentication failed, storedKey mismatch

Platform is Windows 10 x64, if that matters. MongoDB 64-bit 3.2.7 with OpenSSL.

如果重要的话,平台是 Windows 10 x64。MongoDB 64 位 3.2.7 与 OpenSSL。

采纳答案by robertklep

As per the documentation, the object passed to createUsershould contain a userproperty (along with the others):

根据文档,传递给的对象createUser应该包含一个user属性(以及其他属性):

db.createUser({ user : "admin", pwd : "admin", roles : ["root"] })
                ^^^^ not `createUser`

回答by Carlos Brito

Probably you're trying to recreate the database with new login and/or password. So, you need to exclude the "/db" folder. The database path's in the docker-compose.yml file. e.g.: "volumes: - ./db:/data/db".

可能您正在尝试使用新的登录名和/或密码重新创建数据库。因此,您需要排除“/db”文件夹。数据库路径在 docker-compose.yml 文件中。例如:“卷:- ./db:/data/db”。

回答by supertrens

I believe the passwordyou entered on db.createUser doesn't match the one you entered when prompting Enter passwordin the mongo console. You can try to remove the user: db.dropUser('userName')and recreate the user. Make sure you remember the correct password.

我相信password您在 db.createUser 上输入的与您Enter password在 mongo 控制台中提示时输入的不匹配。您可以尝试删除用户:db.dropUser('userName')并重新创建用户。确保您记住正确的密码。