MonogDB 设置明文密码

设置超级管理员账号密码

  • 首先选择
    use admin
  • 设置操作的用户名密码
    db.createUser({user: 'root', pwd: 'pass123*', roles: ['root']})
  • 密码认证
    db.auth('root', 'pass123*')

给单独某个库设置密码

  • 首先选择数据库
    use test_db
  • 再创建用户
    db.createUser({user:"user",pwd:"12345", roles:[{role: 'readWrite',db: 'test_db'}]})

以下操作要看用户加载了那个库,在那个库里操作

  • 删除用户
    db.dropUser('selena')
  • 修改用户密码
    db.updateUser('admin', {pwd: '654321'})

修改配置文件启用明文密码(需要重启服务)

  • 配置文件 /etc/mongod.conf
 # mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /data/mongo/logs/mongod.log

# Where and how to store data.
storage:
  dbPath: /data/mongo/data
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
  #bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

# 这里是开启密码后需要开启的配置
security:
    authorization: enabled

#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容