Replica Set Authentication

Authentication was added in 1.7.5

Replica set authentication works a little differently from single-server authentication, so that each member can automatically authenticate itself to the other members of the set. See the main docs on authentication for details.

Example

If we had a two-member replica set with members a and b, we could start them up with authentication enabled by running:

a$ echo "this is my super secret key" > mykey
a$ chmod 600 mykey
a$ mongod --keyFile mykey # other options...

b$ echo "this is my super secret key" > mykey
b$ chmod 600 mykey
b$ mongod --keyFile mykey # other options...

Then run rs.initiate() and so on.

Using the Database with Replica Set Authentication On

From the client's perspective, authentication works the same way with replica sets as it does with single servers.

For example, suppose you create a new replica set and start the members with --keyFile. Connect to the master locally to add users:

master$ mongo
MongoDB shell version: x.y.z
connecting to: test
> db.addUser("foo", "bar")

Clients should authenticate as usual when they make connections.

any-member$ mongo -u foo -p
MongoDB shell version: x.y.z
Enter password: <bar>

Follow @mongodb

MongoDB Pittsburgh - May 15
MongoNYC - May 23
MongoDB Paris - Jun 14
MongoDB UK - Jun 20
MongoDC - June 26


Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.

blog comments powered by Disqus