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;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM