By default MongoDB does not require username and password to access the data. This is good for development environment, but on production setup we should enable authentication to enhance security. Follow below steps to setup authentication/access control in MongoDB. These steps are performed on Ubuntu machine but should work on any Linux setup. 1. Start MongoDB without access control enabled sudo service mongod start 2. Connect to MongoDB instance mongo --port 27017 3. Switch to 'admin' database user admin; 4. Create admin user This creates a new user in 'admin' database with role as 'userAdminAnyDatabase', which allows user to grant any user any privilege on any database. db.createUser( { user: "<user-admin>", pwd: "<user-admin-password>", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } ) 5. Disconnect mongo shell and stop MongoDB. sudo service mongo
Articles on software development