System specs:
- OS: Debian 10
- Mongo Shell: v4.4.4
- Mongod: v4.4.4
I successfully created a user administrator for MongoDB with the privileges below (output from show users
in Mongo Shell).
{
"_id" : "admin.admin",
"userId" : UUID("eca59ae2-66bd-42a7-b3d8-b946915922b7"),
"user" : "admin",
"db" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
},
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
I also made the necessary updates to /etc/mongod.conf to enable authentication:
security:
authorization: enable
And everything works well when I launch mongod from shell with sudo mongod --auth
. I can connect with credentials with the command:
mongo mongodb://localhost:27017/admin?authSource=admin --username 'admin' --password <mypassword>
I then shutdown mongod and try to start it as a service with: sudo systemctl start mongod
, at which point authentication no longer works. The same mongo connect command shown above now gives the output:
MongoDB shell version v4.4.4
connecting to: mongodb://localhost:27017/admin?authSource=admin&compressors=disabled&gssapiServiceName=mongodb
Error: Authentication failed. :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1
Any ideas what would cause this?