Reputation: 3698
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:
/etc/mongodb.conf
correct? If not what might be the right way?P.S: I created Linux Server from Azure if that helps.
Upvotes: 2
Views: 1791
Reputation: 3698
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.
Upvotes: 1