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:
- Is what I have done for authentication on
/etc/mongodb.confcorrect? If not what might be the right way? - How can I test if authentication is enabled on MongoDb?
P.S: I created Linux Server from Azure if that helps.