Skip to main content

How to enable auth

tip

Enable auth need restart mongo

Requirement to enable auth​

  1. Update security section in mongod.conf
security:
authorization: enabled
  1. Add user to db use <db> → db.createUser(...)

  2. That's all, restart mongo

db.adminCommand( { shutdown: 1 } )

For replica set​

If you enable auth in replica set, make sure create a key by commands below and also add it to configuration file

openssl rand -base64 756 > <path-to-keyfile>
chmod 400 <path-to-keyfile>

And in configuration mongod.conf file:

security:
authorization: enabled
keyFile: <path-to-file>