mongo 的命令行身份验证失败 [英] command line authentication of mongo fails

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

问题描述

我在 osx 上运行 mongo 2.2.2.

I am running mongo 2.2.2 on osx.

当我执行以下身份验证时,一切正常:

When I do the following authentication is going fine:

$ mongo
>> use admin
>> db.auth("uname", "password")

日志:

Thu Mar  7 13:51:08 [initandlisten] connection accepted from 127.0.0.1:63474 #10 (4 connections now open)
Thu Mar  7 13:51:08 [conn10]  authenticate db: admin { authenticate: 1, nonce: "123", user: "uname", key: "456" }

但是,当我尝试直接从命令行进行身份验证时:

However when I try to authenticate directly from the commandline:

$ mongo admin -u uname -p password

我收到以下错误:

Thu Mar  7 14:25:52 [initandlisten] connection accepted from 127.0.0.1:63939 #12 (5 connections now open)
Thu Mar  7 14:25:52 [conn12]  authenticate db: admin { authenticate: 1, nonce: "789", user: "uname", key: "147" }
Thu Mar  7 14:25:52 [conn12] auth: key mismatch uname, ns:admin
Thu Mar  7 14:25:52 [conn12] end connection 127.0.0.1:63939 (4 connections now open)

有人知道这是什么原因吗?

Does anyone know what causes this?

推荐答案

包含特殊字符(尤其是美元符号)的密码必须放在单引号中以保护它们免受命令外壳的攻击:

A password containing special characters, especially the dollar sign, has to be put in single quotes to protect them from the command shell:

$ mongo admin -u uname -p 'password'

这篇关于mongo 的命令行身份验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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