Guest User

Untitled

a guest
Feb 25th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. # MongoDB Kickstart in Ubuntu
  2. > Install and enable access control, create Admin and database User via MongoDB Shell
  3.  
  4. ## Installation and Enable Access Control
  5.  
  6. Use apt-get install for installation
  7. ```bash
  8. $ apt-get install mongodb
  9. $ systemctl status mongodb
  10. ```
  11. Access control can be enabled via configuration file which default in `/etc/mongodb.conf` or via parameters when starting mongodb service `--auth`.
  12. 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.
  13.  
  14. ## Create Admin User via Shell
  15.  
  16. Connect to MongoDB service via mongo shell; and create user in database admin.
  17.  
  18. ``` bash
  19. $ mongo
  20. > use admin
  21. > db.createUser({user:"Admin", pwd:"PasswordAdmin", roles:[{role:"userAdminAnyDatabase", db:"admin"}]})
  22. ```
  23. Role `userAdminAnyDatabase` is a built-in role for managing users in the server.
  24. After creating the Admin user change the configuration, restart the service and reconnect.
  25.  
  26. ## Create Database User
  27.  
  28. ``` bash
  29. $ vim /etc/mongodb.conf
  30. # Comment out auth=true, by default configuration use auth=false
  31. $ systemctl restart mongodb
  32. ```
  33.  
  34. Reconnect to the server and authenticate to create other user using `db.createUser` and different role.
  35.  
  36. ```bash
  37. $ mongo
  38. > db.auth("Admin","PasswordAdmin")
  39. > db.createUser({user:"DbUser", password:"DbAdminPass", roles:[{role: "readWrite", db:"db_name"}]})
  40. ```
Add Comment
Please, Sign In to add comment