In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces MongoDB4.28 how to open the user password login function, the content is very detailed, interested friends can refer to, I hope to help you.
MongoDB does not enable authorization authentication by default. As long as you can connect to this server, you can connect to mongod. To enable security authentication, you need to change the parameter auth in the configuration file montdb. conf.
MongoDB users are associated with databases. Specific databases need corresponding users. Super administrators cannot operate other databases.
MongoDB stores all user information in the admin database collection system.users, saving user names, passwords, and database information.
MongoDB open permission authentication: configure user name and password authentication login, operation steps:
The requested URL/usr/local/mongodb/bin$cat mongodb.conf was not found on this server.
#Data file storage directory
dbpath = /usr/local/mongodb/data
#Log file storage directory
logpath = /usr/local/mongodb/logs/mongodb.log
logappend=true
#Port
port = 27017
#Enabled as a daemon, i.e. running in the background
fork = true
#Authentication mode (true means authentication login is enabled, false means authentication login is not enabled)
auth=false
#Remote connection
bind_ip=0.0.0.0
2, Open user name and password authentication (create users need to enter the admin database)2.1, Create an administrator account for the admin database
1. Database admin Create an administrator account
[root@hadoop-master bin]# mongo> use admin> db.createUser({user:"root",pwd:"lianshi",roles:["root"]})
2. View current users
> show users2.2, Create regular users for database mytest
1. Create cg user for database mytest
>use mytest> db.createUser({user:"cg",pwd:"lianshi",roles:[{role:"readWrite",db:"mytest"}]})
2. View current users
> show users>db.system.users.find() command to view the newly created user 2.3. Enable username password authentication #authentication mode (true means authentication login is enabled, false means authentication login is not enabled)auth=true3. Restart mongo service [root@hadoop-master bin]# ps -ef| grep mongo[root@hadoop-master bin]# kill -9 15231$./ mongod -f mongodb.conf4, mongo authorized access 4.1, admin database authorized login
1, mongo visit
[root@hadoop-master bin]# mongo> use adminswitched to db admin> show users2020-06-21T20:14:59.735+0800 E QUERY [js]uncaught exception: Error: command usersInfo requires authentication :_getErrorWithCode@src/mongo/shell/utils.js:25:13DB.prototype.getUsers@src/mongo/shell/db.js:1638:15shellHelper.show@src/mongo/shell/utils.js:883:9shellHelper@src/mongo/shell/utils.js:790:15@(shellhelp2):1:1 --> After authorizing the configuration and restarting, check the user at this time and you will find that there is no permission
2. Log in with user and password
> db.auth("root","lianshi")
---> Use db.auth("root","lianshi") to enable auth authentication, see that the return value is 1, which means that the boot is successful, and then we use the command to view the user and database.
4.1 mytest database authorization login
1, mongo visit
> use mytest;switched to db mytest> show users2020-06-21T21:25:41.293+0800 E QUERY [js]uncaught exception: Error: command usersInfo requires authentication :_getErrorWithCode@src/mongo/shell/utils.js:25:13DB.prototype.getUsers@src/mongo/shell/db.js:1638:15shellHelper.show@src/mongo/shell/utils.js:883:9shellHelper@src/mongo/shell/utils.js:790:15@(shellhelp2):1:1 --> Error Not allowed
2, user and password login user
> db.auth("cg","lianshi");
Enable auth authentication using db.auth("cg","lianshi") and see that the return value is 1, which means that the startup is successful, and then we use the command to view the user and database.
> show dbsmytest 0.000GB> db.student.insert({"id":"2","name":"yxy"})WriteResult({ "nInserted" : 1 })
Other user commands:
1. Create an ordinary user (create user cg, read and write permission to mytest database)
> db.createUser({user:"cg",pwd:"lianshi",roles:[{role:"readWrite",db:"mytest"}]})
2, Delete user>db.dropUser("yonghu")
3. Change user password
db.updateUser("cg",{pwd:"123456"})
4. Enter data mytest, username password authentication
> db.auth("cg","lianshi");
5. Client tools authorize login to connect to mongo database
User name and password to connect to database
About MongoDB4.28 how to open the authorization configuration user password login function to share here, I hope the above content can have some help for everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.