$> sudo apt-get install -y mongodb
$> mongo
$> use admin
Please note: only change user and password not change to role and db
$> db.createUser({ user: "admin", pwd: "pwd@123", roles: [{ role: "userAdminAnyDatabase", db: "admin" }] })
To check user auth
$> db.auth("admin", "hate2wait@123")
$> 1
create normal user
$> use db_production
$> db.createUser({ user: "myname", pwd: "anypassword", roles: [{ role: "dbOwner", db: "db_production" }] })
$> db.auth("myname", "anypassword")
$>
$> sudo nano /etc/mongodb.conf
# Turn on/off security. Off is currently the default
#noauth = true
auth = true
Uncomment auth = true
ctrl + x
No comments:
Post a Comment