Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # MongoDB Kickstart in Ubuntu
- > Install and enable access control, create Admin and database User via MongoDB Shell
- ## Installation and Enable Access Control
- Use apt-get install for installation
- ```bash
- $ apt-get install mongodb
- $ systemctl status mongodb
- ```
- Access control can be enabled via configuration file which default in `/etc/mongodb.conf` or via parameters when starting mongodb service `--auth`.
- Before enable access control create an Admin User first, this admin have the privileges to create user and give access to any database in the server.
- ## Create Admin User via Shell
- Connect to MongoDB service via mongo shell; and create user in database admin.
- ``` bash
- $ mongo
- > use admin
- > db.createUser({user:"Admin", pwd:"PasswordAdmin", roles:[{role:"userAdminAnyDatabase", db:"admin"}]})
- ```
- Role `userAdminAnyDatabase` is a built-in role for managing users in the server.
- After creating the Admin user change the configuration, restart the service and reconnect.
- ## Create Database User
- ``` bash
- $ vim /etc/mongodb.conf
- # Comment out auth=true, by default configuration use auth=false
- $ systemctl restart mongodb
- ```
- Reconnect to the server and authenticate to create other user using `db.createUser` and different role.
- ```bash
- $ mongo
- > db.auth("Admin","PasswordAdmin")
- > db.createUser({user:"DbUser", password:"DbAdminPass", roles:[{role: "readWrite", db:"db_name"}]})
- ```
Add Comment
Please, Sign In to add comment