1 to see if there is a shell in the mongo process>
ps -aux | grep mongo
2 Kill the existing process to start in unauthenticated mode
sudo ./bin/mongod --dbpath=/opt/db/mongodb/data --logpath=/opt/db/mongodb/logs/mongo.log --logappend --rest --fork --maxConns=20000 --config /etc/mongodb.conf
3 Create an administrative user and
enter mongo >
./bin/mongo ; use admin
db.createUser({user: "root",pwd: "root",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})
4 Restart the mongodb service to add instructions that must be authenticated to operate
sudo ./bin/mongod --dbpath=/opt/db/mongodb/data --logpath=/opt/db/mongodb/logs/mongo.log --logappend --rest --fork --auth --maxConns=20000 --config /etc/mongodb.conf
Before restarting the service, you can modify the configuration file to allow external IP connections
to allow all IP connections to
configure the mongodb.conf file to add
bindIp=0.0.0.0
5 Enter the terminal to verify the management user
db.auth("root","root")
6 Enter the custom database
use rlink
create user
db.createUser({user:"link_user",pwd:"123456",roles:[{"role":"readWrite","db":"rlink"}]})
7 Complete User Authentication
shell> use rlink
shell> db.auth("link_user","123456")
8 Adding a super user can not only authorize but also perform arbitrary operations on any collection.
Follow the above order. When adding an administrative user, modify its role to root
db.createUser({user: "admin",pwd: "adminjfn",roles: [ { role: "root", db: "admin" } ]})