简体   繁体   English

身份验证MongoDB

[英]Authentication MongoDB

Anyone can help me? 有人可以帮助我吗?

I am trying to authentication a user in my database but i am geting error "auth fails". 我正在尝试对数据库中的用户进行身份验证,但出现错误“身份验证失败”。

I've already started the database mongod with --auth option and created a user in my database. 我已经使用--auth选项启动了数据库mongod并在数据库中创建了一个用户。 But when i try to run command -> "mongo 192.168.2.2/db_name -u user -p 123" it says "auth fails" 但是,当我尝试运行命令-> "mongo 192.168.2.2/db_name -u user -p 123"它说"auth fails"

The pass and the user is the same. 通行证和用户相同。 The user has all admin and cluster roles. 该用户具有所有管理员和群集角色。 If i try to log without admin roles it says "Not authorized for query on admin.system.users" 如果我尝试在没有管理员角色的情况下登录,则会显示“未授权在admin.system.users上进行查询”

running the command db.auth("user","123") returns true to me. 运行命令db.auth("user","123")对我返回true。 i've already tried to add the user with db.addUser("user","123") and db.addUser({name: "user", pwd: "123", roles: ["dbAdmin", "userAdminAnyDatabase", "clusterAdmin"]}) 我已经尝试使用db.addUser("user","123")db.addUser({name: "user", pwd: "123", roles: ["dbAdmin", "userAdminAnyDatabase", "clusterAdmin"]})

Any tips? 有小费吗?

If you no have setParameter = enableLocalhostAuthBypass=0 in your config, join in mongo shell without loggin, of course, loggin in admin db and add user in all databases. 如果您的配置中没有setParameter = enableLocalhostAuthBypass=0 ,请加入mongo shell而无需登录,当然,请登录admin db并在所有数据库中添加用户。

you can use this 你可以用这个

First join in admin database . 首先加入admin数据库

First Method 第一种方法

db.addUser({user: "test",pwd:"123", roles: [ "readWrite", "dbAdmin", "userAdminAnyDatabase", "clusterAdmin"], otherDBRoles:{otherdb1: [ "readWrite", "dbAdmin" ]}})

Second Method 第二种方法

db.addUser("test","123")
db.auth("test","123")

and repeat this in all databases. 并在所有数据库中重复此操作。

Differences: 区别:

First method only have all privilegies when you loggin directly in admin db , but if you loggin in other db with admin user, wont work because you have this user in admin db, no in others db. 当您直接在admin db中登录时,第一种方法仅具有所有特权 ,但是如果您以admin用户登录其他db,则将无法工作,因为您在admin db中拥有此用户,而在其他db中则没有。

Second method if you loggin in any databases you have all roles in all db. 第二种方法,如果您登录任何数据库,则在所有数据库中都具有所有角色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM