2

I have installed mongodb on Linux Server - Ubuntu 16.04. It is up and running, as I have tested it through putty. So, next thing I wanted to do was setup authentication on mongodb.

I have created users with roles following this blog.

This is my etc/mongodb.conf

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1
security:
  authorization: enabled

I have setup user in db in system.users collection for two dbs with roles and restarted mongod on server.

Here, is the script test.sh to test the authentication status of mongodb. Ref was taken from here.

#!/bin/bash

# Connect to MongoDB address (host:port/dbname) specified as first parameter
# If no address specified, `mongo` default will be localhost:27017/test
isAuth=`mongo --eval "db.getUsers()" $1 | grep "not auth"`

if [ -z "$isAuth" ] ;
then
   echo "mongod auth is NOT enabled"
   exit 1
else
   echo "mongod auth is ENABLED"
   exit 0
fi

When I run the script I got mongod auth is NOT enabled. Moreover, I am also not having problem inserting or viewing database form shell.

So, my questions in summary are:

  1. Is what I have done for authentication on /etc/mongodb.conf correct? If not what might be the right way?
  2. How can I test if authentication is enabled on MongoDb?

P.S: I created Linux Server from Azure if that helps.

1 Answer 1

1

Sorry to say but it was a typo I was doing systemctl start mongodb, it was actually mongod.

systemctl start mongod

made it up and running. I hope the resources I used for enabling authorization on Mongodb and Bash Script to check if authorization is working, will be a good resources for developers starting to develop using MongoDB.

Sign up to request clarification or add additional context in comments.

1 Comment

same here! I had done the exact same miss-type! You have saved me long hours of slog that would have gone nowhere! One beer to you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.