I am having trouble getting basic Mongo security to work on my ubuntu 14.04 instance. I installed Mongo 3.2 My /etc/mongod.conf file has no auth, so when starting mongo via sudo service mongod start (or on boot), I can edit security information from the mongo console. There was a chance that I messed up my auth system previously by peforming a db.system.version.remove({}), and then a db.system.version.insert({ "_id" : "authSchema", "currentVersion" : 3 }), so to fix this (or just be safe), I deleted all the users and ran the following per https://docs.mongodb.org/v3.0/release-notes/3.0-scram/#upgrade-scram-scenarios.
db.adminCommand({authSchemaUpgrade: 1});
This resulted in an okay. I then created my admin user as follows:
use admin
db.createUser( { user: "siteUserAdmin", pwd: "PASSWORD", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } )
This returned the result of the created user. I then tested it (still with the current mongod instance with auth turned off) by doing:
use admin
db.auth(siteUserAdmin, "PASSWORD")
This returned a 1 success, so far so good, looks like the user is working. Next I stop start mongod in one of two ways to attempt to enable security. One is editing the /etc/mongod.conf file to include authorization: enabled underneath the #security section. sudo service mongod start then would not work (although it said running, a subsequent sudo service mongod status showed stopped and I cannot connect in shell). So, I have had better results with starting mongod as a daemon service as recommended in https://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/:
mongod --fork --logpath /var/log/mongodb.log --auth --port 27017 --dbpath /var/lib/mongodb/admin
This works and I can access the Mongo console, then I enter use admin, this switches to db admin successfully, then I attempt again:
db.auth(siteUserAdmin, "PASSWORD")
Heres my problem/question, now I get a 0, Error: Authentication failed. I have tried a number of things not worth mentioning and can't seem to authenticate, please exuse the long question I think the extra circumstances may have to do with the issue, any ideas what I'm doing wrong?