MongoDB权限
发表于:2025-02-24 作者:千家信息网编辑
千家信息网最后更新 2025年02月24日,1. 添加用户MongoDB shell version: 1.8.2connecting to: 127.0.0.1:30000/test>>>> use adminswitched to db a
千家信息网最后更新 2025年02月24日MongoDB权限1. 添加用户
MongoDB shell version: 1.8.2
connecting to: 127.0.0.1:30000/test
>
>
>
> use admin
switched to db admin
> db.addUser('admin','admin')
{
"user" : "admin",
"readOnly" : false,
"pwd" : "7c67ef13bbd4cae106d959320af3f704"
}
>
2. 带上--auth参数后重启
$MONGODB_HOME/bin/mongod --fork --logpath=$MONGODB_HOME/logs/mongodb.log --dbpath=$DATA_PATH --port=$MONGODB_PORT --auth
3. 测试
MongoDB shell version: 1.8.2
connecting to: 127.0.0.1:30000/test
>
> use admin
switched to db admin
> show collections
Sat Aug 6 11:16:45 uncaught exception: error: {
"$err" : "unauthorized db:admin lock type:-1 client:127.0.0.1",
"code" : 10057
}
switched to db admin
> db.auth('admin','admin')
1
> show collections
system.indexes
system.users
> 没有执行db.auth('admin','admin')之前会报错,说是未授权
4. Java客户端调用也需要使用用户名和密码,只需简单地加上一句
db.authenticate("admin", "admin".toCharArray());
5. 在admin下添加的用户是超级管理员,可以访问任何数据库,用超级管理员可以为单个数据库添加用户,这个用户只能访问他所在的数据库
> use test
switched to db test
> db.addUser("test","test")
{
"user" : "test",
"readOnly" : false,
"pwd" : "a6de521abefc2fed4f5876855a3484f5"
}6. 在未授权的情况下,依然可以执行
db.shutdownServer()停掉节点
所以运行mongodb的服务器端口一定要严格授权访问
MongoDB shell version: 1.8.2
connecting to: 127.0.0.1:30000/test
>
>
>
> use admin
switched to db admin
> db.addUser('admin','admin')
{
"user" : "admin",
"readOnly" : false,
"pwd" : "7c67ef13bbd4cae106d959320af3f704"
}
>
2. 带上--auth参数后重启
$MONGODB_HOME/bin/mongod --fork --logpath=$MONGODB_HOME/logs/mongodb.log --dbpath=$DATA_PATH --port=$MONGODB_PORT --auth
3. 测试
MongoDB shell version: 1.8.2
connecting to: 127.0.0.1:30000/test
>
> use admin
switched to db admin
> show collections
Sat Aug 6 11:16:45 uncaught exception: error: {
"$err" : "unauthorized db:admin lock type:-1 client:127.0.0.1",
"code" : 10057
}
switched to db admin
> db.auth('admin','admin')
1
> show collections
system.indexes
system.users
> 没有执行db.auth('admin','admin')之前会报错,说是未授权
4. Java客户端调用也需要使用用户名和密码,只需简单地加上一句
db.authenticate("admin", "admin".toCharArray());
5. 在admin下添加的用户是超级管理员,可以访问任何数据库,用超级管理员可以为单个数据库添加用户,这个用户只能访问他所在的数据库
> use test
switched to db test
> db.addUser("test","test")
{
"user" : "test",
"readOnly" : false,
"pwd" : "a6de521abefc2fed4f5876855a3484f5"
}6. 在未授权的情况下,依然可以执行
db.shutdownServer()停掉节点
所以运行mongodb的服务器端口一定要严格授权访问
用户
数据
数据库
管理员
管理
单个
参数
只需
客户
客户端
密码
情况
所在
服务器
用户名
端口
节点
说是
上一
会报
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
丰县信诚网络技术
迅云服务器
hp服务器ilo
华为软件开发工程师薪酬
文件服务器和oa服务器
杭州伙聚网络技术有限公司
服务器内存条故障维修
怀旧服服务器的主机在哪里
河南2020网络技术模拟试卷
渝中区提供软件开发流程代理商
重庆一站式网络技术服务代理商
garmin 服务器
万题库软件开发
数据库我了
通讯网络技术等级证书
服务器包结构设计图
vba数组写到数据库
网络安全技术经典书籍
保山哪有软件开发定制
日本政府网络安全战略
北京外包软件开发
网络安全宣传片歌曲
工科局 网络安全进校园
软件开发 文档 uml
软件开发费用明细
常用数据库系统的连接方式
数据库驱动程序是什么
软件开发需要投资多少钱
域服务器可管理哪些内容
一般服务器需要多大的机柜