Mongo user and authentication login

background

创建角色,并赋权

https://www.cnblogs.com/keme/p/11004955.html
link

# 创建角色
db.createRole( { role: “test”, privileges: [ { resource: { db: “test”, collection: “” }, actions: [insert,update,remove] }, ], roles: [ { role: “read, db: “test” } ] }, { w: “majority” , wtimeout: 5000 })
# 创建用户,添加到相应角色
db.createUser({
   
   user:"ke",pwd:"123456",roles:[ { role:"test", db:"test" }]})
#查看当前mongo实例有哪些用户
> db.getUsers()
[ ]
空的,没有用户
 
# 创建用户
> db.createUser({
   
   user: "admin",pwd: "123456",roles:[ { role: "root", db:"admin"}]})
Successfully added user: {
    "user" : "admin",
    "roles" : [
        {
            "role" : "root",
            "db" : "admin"
        }
    ]
}
# 查看用户
> db.getUsers()
[
    {
        "_id" : "test.admin",
        "user" : "admin",
        "db" : "test",
        "roles" : [
            {
                "role" : "root",
                "db" : "admin"
            }
        ]
    }
]

User authentication profile

末尾添加如下两行内容
 vim /opt/mongodb/conf/mongodb.conf
security: #认证
   authorization: enabled #启用或者禁用基于角色的访问控制来管理每个用户对数据库资源和操作的访问enabled 或者 disables
 
#重启生效
 mongod -f /opt/mongodb/conf/mongodb.conf --shutdown
killing process with pid: 79647
 mongod -f /opt/mongodb/conf/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 93037
child process started successfully, parent exiting

配置问权限认证后需要重启节点,再次登陆如果不使用账号密码就查看不了数据 db.auth("keme","123456")

This article explains that the main technical content comes from the sharing of Internet technology giants, as well as some self-processing (only for the role of annotations). If related questions, please leave a message after the confirmation, the implementation of infringement will be deleted

Guess you like

Origin blog.csdn.net/baidu_34007305/article/details/110238564