|
Authentication is enforced when access control is enabled on a MongoDB deployment, requiring users to identify themselves. Users can only conduct activities that are defined by their roles when visiting a MongoDB deployment with access control enabled. In this article, We will utilize the default authentication approach to provide access control on a solo Mongo instance and see Authentication Techniques for a list of all supported authentication mechanisms. Administrator of Users
Note: The instance of MongoDB uses port 27017 as well as the location of data /var/lib/mongodb. The example presumes the existence of the data directory, i.e., /var/lib/mongodb. And specify a different data directory as appropriate. How to Enable Authentication on MongoDBFollow the below steps to enable Authentication as defined: Step 1: Open a Mongo Shellmongo
Output: Step 2: Setting Up Administrator and Service Users in MongoDBThe database binstar must be able to read and write to the repository. To establish an administrator user and a service user, run the following commands in the MongoDB shell: use admin
Step 3: To manage database users, create an administrative userdb.createUser({user:'siteUserAdmin', pwd: '<secure password #1>', Output: Step 4: To validate the password, log in as that userdb.auth('siteUserAdmin', '<secure password #1>')
Step 5: Create a Repository service userdb.createUser({user:'spandan', pwd: '<secure password #2>', Step 6: In MongoDB, enable required authentication
auth=true
security: Step 7: To reload the settings, restart MongoDBsudo service mongod restart
Step 8: Set the MONGO URL option in the Repository configuration file to mongodb:/username:password@hostname>. Step 9: Restart Repository after modifying the configuration file to see the changes take effect. Exception for localhost
ConclusionEnabling authentication in MongoDB is essential for securing your database by ensuring that only authorized users can perform specific operations based on their roles. This tutorial provided a step-by-step guide to setting up authentication on a standalone MongoDB instance and creating necessary users with appropriate roles. Following these steps will help maintain the security and integrity of your MongoDB deployment. Frequently Asked QuestionsWhat is the default authentication mechanism in MongoDB?
What happens if I enable access control but do not create any users?
Can I modify the roles of an existing user?
What should I do if I forget the password of the administrative user?
|
Reffered: https://www.geeksforgeeks.org
Databases |
Related |
---|
![]() |
![]() |
|
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |