I'm trying to activate user authorization on my local Mongo installation, but authentication keeps on failing. What can be the problem? Am I missing something?
I followed the steps outlined in "Installing on Windows" and "Enable Client Access Control":
1) Added a user
>mongo admin
MongoDB shell version: 3.2.7
connecting to: admin
> db.createUser({createUser:"admin",pwd:"admin",roles:["root"]})
Successfully added user: { "createUser" : "admin", "roles" : [ "root" ] }
>
2) Enabled Client Access Control in mongod.cfg:
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
security:
authorization: enabled
3) Restarted mongod
4) Now logging in with the "right" credentials (the ones I just specified) always fails:
>mongo admin -u admin -p admin
MongoDB shell version: 3.2.7
connecting to: admin
2016-06-14T12:25:02.376+0200 E QUERY [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow#src/mongo/shell/db.js:1441:20
#(auth):6:1
#(auth):1:2
exception: login failed
The error in the logfile is: SCRAM-SHA-1 authentication failed for admin on admin from client 127.0.0.1 ; AuthenticationFailed: SCRAM-SHA-1 authentication failed, storedKey mismatch
Platform is Windows 10 x64, if that matters.
MongoDB 64-bit 3.2.7 with OpenSSL.
As per the documentation, the object passed to createUser should contain a user property (along with the others):
db.createUser({ user : "admin", pwd : "admin", roles : ["root"] })
^^^^ not `createUser`
Probably you're trying to recreate the database with new login and/or password. So, you need to exclude the "/db" folder. The database path's in the docker-compose.yml file. e.g.: "volumes: - ./db:/data/db".
If someone came here with the error message, this may help:
MongoDB cannot handle several symbols;
Restrictions on Database Names for Windows
For MongoDB deployments running on Windows, database names cannot contain any of the following characters:
/\. "$*<>:|?
Also database names cannot contain the null character.
Restrictions on Database Names for Unix and Linux Systems
For MongoDB deployments running on Unix and Linux systems, database names cannot contain any of the following characters:
/\. "$
https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names
I stuck on the error 'Authentication failed' with mongoengine as well as pymongo.
Please change your password when containing the symbols.
I believe the password you entered on db.createUser doesn't match the one you entered when prompting Enter password in the mongo console. You can try to remove the user: db.dropUser('userName') and recreate the user. Make sure you remember the correct password.
Related
I'm trying to shutdown mongodb so that I can convert it to a replica set, but I keep getting an error.
when using db.shutdownServer(), I get
"errmsg" : "not authorized on admin to execute command
I tried "use admin" and then running the command, but issue still persists.
I saw another post where they said to use db.auth(username, password) but if I type that in cmd after connecting to cluster
When I try db.auth(username, password) replacing username and password with actual values
I get
SyntaxError: missing ) after argument list
I'm still new to mongodb so any help is appreciated.
can you share the piece of code.
you can rewrite the above command with
passwordPrompt() option
db.auth( "username", passwordPrompt() )
or
mongo --username "" --password -- --authenticationMechanism SCRAM-SHA-256
I followed the instructions here for setting up users...
Then from another machine I do:
mongo -u admin -p adminpassword host/collection
The response I get is:
MongoDB shell version: 2.6.10 connecting to: host/collection
2019-07-12T06:20:36.336+0000 Error: 2 { ok: 0.0, errmsg: "Auth
mechanism not specified", code: 2, codeName: "BadValue" } at
src/mongo/shell/db.js:1287 exception: login failed
Now, I suppose this is an issue with different versions but what I'm really after is to remote connect from a node script and that's failing as well but the only message is: "MongoError: Authentication failed."
Does anyone know a solution?
Ran into the same issue when using an old Mongo shell version (2.x/3.x) with a 4.0+ server. Upgrading the Mongo shell to 4.0.6+ seems to have resolved the issue.
My guess is the protocol to authenticate and specifying auth mechanisms has changed in newer server versions.
Maybe is because you've tried to connect with admin user on a different collection than admin.
Try mongo -u ADMIN_USERNAME -p ADMIN_PASSWORD HOST_IP/admin
I have setup Active directory with kerberos authentication on windows server 2012 r2, set mongodb server on a 2nd machine. Started mongodb with GSSAPI authentication, Now if I try to connect to mongodb using the follwong url
mongo.exe --host Mongo32Test.ihubtest.com.com --authenticationMechanism=GSSAPI --authenticationDatabase=$external -u mongoService#ihubtest.com --verbose
I am getting the following message.
Error: SASL(-1): generic failure: SSPI: InitializeSecurityContext: The specified target is unknown or unreachable
I have installed wireshark and the packet contains this message
"KRB5 167 KRB Error: KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN"
Searching around I figured that it is related to service principle name
mongoService#ihubtest.com is a domain user and is part of $external database in mongodb.
verified the service principle name, it looks fine.
C:>setspn -l mongoService
Registered ServicePrincipalNames for CN=mongo Service,CN=Users,DC=ihubtest,DC=com:
mongodb/Mongo32test.ihubtest.com#IHUBTEST.COM
tried the troubleshooting steps mentioned in this page, https://docs.mongodb.com/manual/tutorial/troubleshoot-kerberos/, am I missing something on Active directory configuration ?
if not yet looked into this ticket MongoDB Team has a closed ticket with some steps
https://jira.mongodb.org/browse/SERVER-13885
I believe in you misquoted your hostname as "Mongo32Test.ihubtest.com.com" instead of "Mongo32Test.ihubtest.com".
Please verify whether the provided hostname is correct or not
I have 2 problems. First I can't login into my MongoDB. I tried this way: Can't create backup mongodump with --db. Authentication failed but no succsess. I've tried differnt passwords and user, but I can't log in. My Mongo Server runs on an Debian 8 Server. For Uninstall and install, I used this tutorial: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/ . I start the debian new after every uninstall.
Can I remove the password. In the conf data, I comment auth = true. I hope you can help me.
I get this message
MongoDB shell version: 3.2.7
connecting to: 127.0.0.1:27017/test
2016-06-29T12:30:01.079+0000 E QUERY [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow#src/mongo/shell/db.js:1441:20
#(auth):6:1
#(auth):1:2
exception: login failed
No authentication by default on mongo that might have to do with system privileges.
I'm beginning to use MongoDB and have spent several hours troubleshooting without resolve. From what I understand, there first needs to be a root user before there can be an authorized/admin user.
I installed in C:\mongodb\, then setup --dbpath in C:\mongodb\data and --logpath in C:\mongodb\logs\log.txt.
I installed then ran the MongoDB service, accessible in the services.msc
My recipe to disaster was:
1. mongo localhost,
2. use admin
3. db.createUser({ user: 'root', pwd: '123456', roles:['root']})
Then get "Error: couldn't add user: not authorized on admin to execute command { createUser ....."
I am running MongoDB shell version: 2.6.5 and greatly appreciate any help that leads to a solution.
Thank you,
Leo
I figured it out. I accidentally put the data and logs in same directory as the \mongodb\bin. The solution is to put the mongodb\data and mongodb\logs in a separate folder or drive -- I differentiated using C:\~ and D:\~ drives.