I've created an admin user for mongo using these directions:
http://docs.mongodb.org/manual/tutorial/add-user-administrator/
From the mongo client it looks like I can authenticate:
> use admin switched to db admin > db.auth('admin','SECRETPASSWORD'); 1 >
But I can't connect any other way. For example:
mongo -u admin -p SECRETPASSWORD
gives the error:
JavaScript execution failed: Error: 18 { code: 18, ok: 0.0, errmsg: "auth fails" } at src/mongo/shell/db.js:L228
I have auth = true
in etc/mongod.conf
.
What am I missing?
If you receive this error message, that means that the username and/or password that you have entered is incorrect. The error message states “Authentication failed! Try again.” You may have locked your account after too many attempts and your account will need to be reset. Contact the Help Desk if this is the case.
SCRAM-SHA-256 is the default authentication method for MongoDB starting in MongoDB 4.0. SCRAM-SHA-256 is a salted challenge-response authentication mechanism (SCRAM) that uses your username and password, encrypted with the SHA-256 algorithm, to authenticate your user.
Authentication is managed at a database level. When you try to connect to the system using a database, mongo actually checks for the credentials you provide in the collection <database>.system.users
. So, basically when you are trying to connect to "test", it looks for the credentials in test.system.users
and returns an error because it cannot find them (as they are stored in admin.system.users
). Having the right to read and write from all db doesn't mean you can directly connect to them.
You have to connect to the database holding the credentials first. Try:
mongo admin -u admin -p SECRETPASSWORD
For more info, check this http://docs.mongodb.org/manual/reference/privilege-documents/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With