title: MongoDB Authentication not enabled on Linux Server
body: <p>I have installed <code>mongodb</code> on Linux Server - Ubuntu 16.04. It is up and running, as I have tested it through <code>putty</code>. So, next thing I wanted to do was setup authentication on <code>mongodb</code>.</p>
  
  <p>I have created users with roles following this <a href="https://www.cyberciti.biz/faq/how-to-secure-mongodb-nosql-production-database/" rel="nofollow noreferrer">blog</a>.</p>
  
  <p>This is my <code>etc/mongodb.conf</code></p>
  
  <pre><code># network interfaces
  net:
    port: 27017
    bindIp: 127.0.0.1
  security:
    authorization: enabled
  </code></pre>
  
  <p>I have setup user in <code>db</code> in <code>system.users</code> collection for two <code>dbs</code> with roles and restarted <code>mongod</code> on server. </p>
  
  <p>Here, is the script test.sh to test the authentication status of mongodb. Ref was taken from <a href="https://stackoverflow.com/questions/31949586/how-to-find-if-mongodb-is-running-in-auth-mode-in-shell-script">here</a>.</p>
  
  <pre><code>#!/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
  </code></pre>
  
  <p>When I run the script I got <code>mongod auth is NOT enabled</code>. Moreover, I am also not having problem inserting or viewing database form shell.</p>
  
  <p>So, my questions in summary are:</p>
  
  <ol>
  <li>Is what I have done for authentication on <code>/etc/mongodb.conf</code> correct? If not what might be the right way?</li>
  <li>How can I test if authentication is enabled on MongoDb?</li>
  </ol>
  
  <p><em>P.S: I created Linux Server from Azure if that helps.</em></p>