create secure database in mongodb

前端 未结 2 1757
眼角桃花
眼角桃花 2021-02-02 03:50

I want to create the database in mongodb that\'s secure.

Secure means the application has to pass username/password to connect to my database in mongodb.

2条回答
  •  天涯浪人
    2021-02-02 04:10

    • Create a Admin user for the mongo instance,

    > use admin

    > db.addUser("admin", "xyzxyz")

    • Switch to db for which authentication is required

    > use newdb

    > db.addUser("newuser", "strongpwd")

    • Stop the mongo instance/service. If mongodb was installed via ppa, then it is configured as a service.

    sudo service mongodb stop

    If it was installed from source, stop the process using:

    /etc/init.d/mongodb stop

    • Change the config file to use authentication by default

    vim /etc/mongodb.conf

    auth = true

    • Start mongodb. If it is a service

    sudo service mongodb restart

    else

    mongod --config /etc/mongodb.conf

    • Check if auth is enabled:

    > show collections on newdb should give the error

    "$err" : "not authorized for query on newdb.system.namespaces",
    "code" : 16550
    

    and should work after

    > db.auth("newuser", "strongpwd")

    Now the db newdb is secured.

提交回复
热议问题