MongoDB启用用户名密码身份验证

创建管理员用户
[root@localhost ~]# mongo

use admin
switched to db admin
> db.createUser({user:"admin",pwd:"password",roles:["root"]})
Successfully added user: { "user" : "admin", "roles" : [ "root" ] }

[root@localhost ~]# vim /etc/mongod.conf
security:
  authorization: enabled //冒号后面需要空一格
  
systemctl restart mongod.service

在连接期间进行身份验证,例如:
mongo --port 27017 -u "admin" -p "password" --authenticationDatabase "admin"
1
连接后验证,例如:
use admin
db.auth("admin", "password" )
 

你可能感兴趣的:(MongoDB启用用户名密码身份验证)