SCRAM-SHA-1
is a default authentication method in MongoDB.
- Let create a new user for authentication purpose:
mongo
use admin
db.createuser({user: 'kirby', pwd: 'password', roles: ['root']})
exit
- Kill any
mongod
processes if necessary. - Create a new mongod configuration file with
authorization
enabled:
...
security
authorization: 'enabled'
...
- Start new
mongod
processes withauthorization
enabled:
mongod --config <CONFIG_FILE>
- To be authorized while connecting through
mongo
, we should storedauthorization
data:
mongo -u <USERNAME> -p <PASSWORD> --authenticationDatabase <DATABASE_NAME>