Ranjith Ramachandra
Ranjith Ramachandra

Reputation: 10764

How to set mongodb to start with authentication automatically

I have mongo setup at an ubuntu host. It currently has no authentication

Mongodb was installed through instructions at http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

I need to add authentication to it.

These links say as to how to do it 1. http://docs.mongodb.org/manual/tutorial/add-user-administrator/ 2. http://docs.mongodb.org/manual/tutorial/enable-authentication/

I start mongodb with the command sudo service mongodb start/restart/stop

How do we make sure that auth is enabled when we use this method

Upvotes: 3

Views: 2189

Answers (2)

ramazan polat
ramazan polat

Reputation: 7880

UPDATE: The following answer was correct for the time question asked (MongoDB 2.x) but it is outdated for current versions of MongoDB. Please consider the answer below for the current versions and upvote it instead.

Use this to ensure mongodb starts with authentication enabled:

echo "auth=true" >> /etc/mongod.conf
service mongodb restart

Upvotes: 4

Gert van den Berg
Gert van den Berg

Reputation: 2756

Ensure that this is present in /etc/mongod.conf:

security:
  authorization: enabled

(The current answer seems to be for an old version and might have been correct at the time that it was posted)

Also see here

Upvotes: 3

Related Questions