authentication in MongoDB and Ubuntu - mongodb

We installed MongoDB on windows(development) version 3.4, and enabled authentication, after running the command mongod --auth, the authentication was successfully implemented.
Now on the production server that is Ubuntu 16, with MongoDb version 4.0, we made changes to the mongod.conf file as seen below and then restated the mongod service with command sudo service mongod start, but now we are not able to connect to our MongoDB Ubuntu server.
security:
authorization: "enabled"
Where did we go wrong in implementing authentication for MongoDB on Ubuntu server.

security:
authorization: "enabled"
2 possible issues here : reading the doc, i'm not sure you need to quote the enabled word.
Moreover, yaml format need to increment sub part of conf, so your conf file have to look like :
security:
authorization: enabled
But cannot really test, since i don't have any running local instance

Related

Enable authorization in MongoDB

I created some mongodb users and when I tried to enable Authorization I added this directive
security:
authorization: "enabled"
to /etc/mongod.config file, and when I restarted mongod it won't start and it exited with error.
My mongodb is version 5.x as a replicaset of three nodes.
Any thoughts?

Enabling authorization in mongod.cfg makes server crash

I am trying to enable mongodb authorization on my local machine (windows 10) I do this by adding the following settings in my mongod.cfg file.
#security:
authorization: "enabled"
When I do this and try to restart mongodb server as service on windows, it crashes with this messages, windows could not start mongodb server.
I tried to start mongodb service through terminal, with following command.
net start Mongodb.
this also gives and error, with message access is denied.
NOTE: without adding authorization configuration in monogd.cfg file, server works fine.
It must be this (without hashtag and with spaces) :
security:
authorization: enabled

How to disable anonymous access to MongoDB 3.0.x in linux

we are using centos 7 , mongodb 3.0.8
Im trying to disable anonymous access to mongodb.
Place auth = true in /etc/mongod.conf disabling anonymous access in version 2.x
but in version 3 when i place the same , the server it self not starting
When i hard search , i found in the mongo docs that in version 3.x
security.authorization should be placed in /etc/mongod.conf
Could any one please help me how to place security.authorization in config file.
add the following to the mongod.conf file:
security:
authorization: enabled

Not authorized for command: addShard on database admin

I'm building a MongoDB cluster using shards of replica sets and have the first replica set setup and three config servers running (all on Linux servers) with a mongos instance running pointing to the three config servers, but when connecting to the mongos instance on the application server (on Windows Server 2012 Standard x64) via the mongo shell and issuing the sh.addShard() command as per the docs, I get the following response:
> sh.addShard("rs1/xxx:xxx")
{
"note" : "not authorized for command: addShard on database admin",
"ok" : 0,
"errmsg" : "unauthorized"
}
Does anyone know what I'm doing wrong? I'm running all Mongo instances using a keyfile for security. The keyfile is a Windows compatible one as per these docs.
My results:
If your data nodes use keyfile based authentication, all the mongod and mongos instances (data, config, etc) need to use --keyFile as well and point to an exact copy of the keyfile.
Secondly, make sure you "use admin" after connecting to config servers using mongos. If this doesn't get you there then add an admin user at the mongos prompt, authenticate with those credentials and try again.
I've since solved this. It was because authentication was enabled by virtue of the keyfile and using the localhost connection wasn't enough to authenticate. After disabling keyfile usage across the cluster, creating an admin account and using that to connect, it worked.
in addition to bisharkha's answer, here is one more clue to use keyfile.
after use admin command, also make sure you have authenticated with:
db.auth("user", "passwd")
It also can happen when you specify wrong name of your collection.

How can I restart mongodb with --auth option in Ubuntu 10.04?

Well, restarting works with stop and start command, but I cannot seem to execute the mongodb command with --auth option.
root#random:/home/random/public_html# mongodb stop
root#random:/home/random/public_html# start mongodb --auth
start: invalid option: --auth
root#random:/home/random/public_html# start mongodb
mongodb start/running, process 29473
root#random:/home/random/public_html#
How can I start mongodb with --auth option?
Edit /etc/mongod.conf and add a line like this:
auth=true
Then:
service mongod restart
See this page for more configuration options: http://www.mongodb.org/display/DOCS/File+Based+Configuration
For MongoDB latest versions 3.x above code wont work, below code in mongod.conf if you are using mongodb 3.x
security:
authorization: enabled
If you are using MongoDB 3, setting auth = true wont work. You will instead need the following in your /etc/mongod.conf
security:
authorization: enabled
For mongodb version 3.2
this is the correct config
security:
authorization: "enabled"
in String format
Just want to supplement the answer. For MongoDB 3, the /etc/mongod.conf has changed. Either of below enable MondgoDB authorization option (--auth):
security:
keyFile: [The path to a key file]
-- or--
security:
authorization: enabled
Details can be found here
you should put the --auth option in the startup script
/etc/rc[0-6].d/mongod