MongoDB默认是不需要输入User和password,客户端就可以登录了 。这个安全问题是很严重的。网上也有很多例子了,但是也有很多细节 许多人都没注意到 我这里顺便提一下。下面说下如何设置用户名和密码。
添加用户的时候必须在1.有相关权限的情况下(后面会说)2.mongod没有加 --auth的情况下。(如果加了,你添加权限的话 会出现下面的情况)
- > use admin
- switched to db admin
- > db.addUser("sa","sa")
- Fri Jul 22 14:31:13 uncaught exception: error {
- "$err" : "unauthorized db:admin lock type:-1 client:127.0.0.1",
- "code" : 10057
- }
- >
所以我们添加用户时 必须先在没有加 --auth的时候 添加个super admin服务起来后,进入./mongo
- ^_^[root@:/usr/local/mongodb/bin]#./mongo
- MongoDB shell version: 1.8.2
- connecting to: test
- > use admin
- switched to db admin
- > db.adduser("sa","sa")
- Fri Jul 22 14:34:24 TypeError: db.adduser is not a function (shell):1
- > db.addUser("sa","sa")
- {
- "_id" : ObjectId("4e2914a585178da4e03a16c3"),
- "user" : "sa",
- "readOnly" : false,
- "pwd" : "75692b1d11c072c6c79332e248c4f699"
- }
- >
这样就说明 已经成功建立了,然后我们试一下权限
- > show collections
- system.indexes
- system.users
在没有加--auth的情况下 可以正常访问admin喜爱默认的两个表
- > db.system.users.find()
- { "_id" : ObjectId("4e2914a585178da4e03a16c3"), "user" : "sa", "readOnly" : false, "pwd" : "75692b1d11c072c6c79332e248c4f699" }>
已经成功建立。
下面把服务加上--auth的选项再进入./mongo- MongoDB shell version: 1.8.2
- connecting to: test
- > use admin
- switched to db admin
- > show collections
- Fri Jul 22 14:38:49 uncaught exception: error: {
- "$err" : "unauthorized db:admin lock type:-1 client:127.0.0.1",
- "code" : 10057
- }
- >
可以看出已经没有访问权限了
MongoDB中级---->大数据量下MapReduce取代GroupBy在Oracle 11g Streams单向传输的基础上配置Streams双向传输测试相关资讯 MongoDB
- MongoDB 3.3.0 发布下载 (01月14日)
- 使用MongoDB C#官方驱动操作 (12/31/2015 16:27:56)
- CentOS 6.6下安装MongoDB 3.0.1 (12/21/2015 19:29:02)
| - MongoDB 3.2版WiredTiger存储引擎 (01月02日)
- 进程监控工具Supervisor 启动 (12/26/2015 10:49:57)
- MongoDB 3.2.1 RC0 发布下载 (12/18/2015 11:32:29)
|
本文评论 查看全部评论 (0)