mongodb初始化用户,也可当作强制破解密码方式

mongodb安装后初始化,也可当作强制破解密码教程

1.关闭认证密码,重新启动mongodb

port=27000
dbpath=/nas/mongodb/data
logpath=/nas/mongodb/logs/mongodb27000.log
logappend=true
fork=true
#屏蔽安全认证
auth=false
maxConns=5000

systemctl restart mongodb

2.进入命令端重置密码

mongo --port 27000
use admin
此次操作需谨慎,会删除所有账号,新数据库默认没有,不需执行,直接创建用户
db.system.users.remove({}) --> 删除所有用户

db.createUser({ user: "root", pwd: "123456", roles: [ { role: "root", db: "admin"} ]}) 
#mongo --port 27000
MongoDB shell version v4.2.3
connecting to: mongodb://127.0.0.1:27000/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("d4d98328-e6a8-413a-8588-b198bf17e6cc") }
MongoDB server version: 4.2.3
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2020-03-18T14:54:36.536+0800 I  CONTROL  [initandlisten] 
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] 
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] 
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] 
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-03-18T14:54:36.537+0800 I  CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

> 
> 
> 
> use admin
switched to db admin
> db.system.user.removed({})
2020-03-18T14:58:46.820+0800 E  QUERY    [js] uncaught exception: TypeError: db.system.user.removed is not a function :
@(shell):1:1
> db.createUser({user:"root",pwd:"54321",roles:[{role:"root",db:"admin"}]})
Successfully added user: {
	"user" : "root",
	"roles" : [
		{
			"role" : "root",
			"db" : "admin"
		}
	]
}
> 

3.将第一步操作屏蔽掉的配置auth=false删掉或注释掉,然后重启

mongo admin -u root -p "54321" --port 27000

> use admin;
switched to db admin
> 
> 
> 
> db.auth
function() {
    var ex;
    try {
        this._authOrThrow.apply(this, arguments);
    } catch (ex) {
        print(ex);
        return 0;
    }
    return 1;
}
posted @ 2020-03-18 15:12  chenlive  阅读(980)  评论(0编辑  收藏  举报