自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

MongoDB權(quán)限管理之用戶名和密碼的操作

數(shù)據(jù)庫 其他數(shù)據(jù)庫 MongoDB
MongoDB默認(rèn)是不需要輸入用戶名和密碼,客戶就可以登錄的。但是出于安全性的考慮,我們還是要為其設(shè)置用戶名和密碼。本文主要介紹的是MongoDB權(quán)限管理之用戶名和密碼的操作,希望能對您有所幫助。

本文我們介紹MongoDB權(quán)限管理,主要介紹的是如何設(shè)置用戶名和密碼。接下來我們就一一介紹。

添加用戶的時(shí)候必須滿足以下兩個(gè)條件:

1.有相關(guān)權(quán)限的情況下(后面會說)。

2.mongod沒有加--auth的情況下(如果加了,你添加權(quán)限的話 會出現(xiàn)下面的情況)。

 

  1. > use admin    
  2.  
  3. switched to db admin    
  4.  
  5. > db.addUser('sa','sa')    
  6.  
  7. Fri Jul 22 14:31:13 uncaught exception: error {    
  8.  
  9. "$err" : "unauthorized db:admin lock type:-1 client:127.0.0.1",    
  10.  
  11. "code" : 10057    
  12.  
  13. }    
  14.  
  15. >    

 

所以我們添加用戶時(shí)必須先在沒有加--auth的時(shí)候添加個(gè)super  admin。

服務(wù)起來后,進(jìn)入./mongo。

 

  1. [root@:/usr/local/mongodb/bin]#./mongo    
  2.  
  3. MongoDB shell version: 1.8.2    
  4.  
  5. connecting to: test    
  6.  
  7. > use admin    
  8.  
  9. switched to db admin    
  10.  
  11. > db.adduser('sa','sa')    
  12.  
  13. Fri Jul 22 14:34:24 TypeError: db.adduser is not a function (shell):1    
  14.  
  15. > db.addUser('sa','sa')    
  16.  
  17. {    
  18.  
  19. "_id" : ObjectId("4e2914a585178da4e03a16c3"),    
  20.  
  21. "user" : "sa",    
  22.  
  23. "readOnly" : false,    
  24.  
  25. "pwd" : "75692b1d11c072c6c79332e248c4f699"    
  26.  
  27. }    
  28.  
  29. >    

 

這樣就說明 已經(jīng)成功建立了,然后我們試一下權(quán)限。

 

  1. > show collections    
  2.  
  3. system.indexes    
  4.  
  5. system.users   

 

在沒有加--auth的情況下 可以正常訪問admin喜愛默認(rèn)的兩個(gè)表。

 

  1. > db.system.users.find()    
  2.  
  3. { "_id" : ObjectId("4e2914a585178da4e03a16c3"), "user" : "sa", "readOnly" : false, "pwd" : "75692b1d11c072c6c79332e248c4f699" }>    

 

已經(jīng)成功建立。

下面把服務(wù)加上--auth的選項(xiàng),再進(jìn)入./mongo。

 

  1. MongoDB shell version: 1.8.2    
  2.  
  3. connecting to: test    
  4.  
  5. > use admin    
  6.  
  7. switched to db admin    
  8.  
  9. > show collections    
  10.  
  11. Fri Jul 22 14:38:49 uncaught exception: error: {    
  12.  
  13. "$err" : "unauthorized db:admin lock type:-1 client:127.0.0.1",    
  14.  
  15. "code" : 10057    
  16.  
  17. }    
  18.  
  19. >    

 

可以看出已經(jīng)沒有訪問權(quán)限了。

我們就用自己的密鑰登錄下:

 

  1. > db.auth('sa','sa')    
  2.  
  3. 1   

 

返回1說明驗(yàn)證成功!

再show collections下就成功了。

.....

我們登錄其它表試試:

 

  1. [root@:/usr/local/mongodb/bin]#./mongo    
  2.  
  3. MongoDB shell version: 1.8.2    
  4.  
  5. connecting to: test    
  6.  
  7. > use test    
  8.  
  9. switched to db test    
  10.  
  11. > show collections    
  12.  
  13. Fri Jul 22 14:40:47 uncaught exception: error: {    
  14.  
  15. "$err" : "unauthorized db:test lock type:-1 client:127.0.0.1",    
  16.  
  17. "code" : 10057    
  18.  
  19. }   

 

也需要驗(yàn)證,試試super admin登錄:

  1. [root@:/usr/local/mongodb/bin]#./mongo    
  2.  
  3. MongoDB shell version: 1.8.2    
  4.  
  5. connecting to: test    
  6.  
  7. > use test    
  8.  
  9. switched to db test    
  10.  
  11. > show collections    
  12.  
  13. Fri Jul 22 14:40:47 uncaught exception: error: {    
  14.  
  15. "$err" : "unauthorized db:test lock type:-1 client:127.0.0.1",    
  16.  
  17. "code" : 10057    
  18.  
  19. }    
  20.  
  21. > db.auth('sa','sa')    
  22.  
  23. 0   

 

返回0驗(yàn)證失敗。 

好吧,不繞圈子,其實(shí)super admin必須從admin那么登錄 然后 再use其它表才可以。

 

  1. > use admin    
  2.  
  3. > use admin  
  4.  
  5. switched to db admin    
  6.  
  7. > db.auth('sa','sa')    
  8.  
  9. 1    
  10.  
  11. > use test    
  12.  
  13. switched to db test    
  14.  
  15. > show collections    
  16.  
  17. >    

 

如果想單獨(dú)訪問一個(gè)表,用獨(dú)立的用戶名,就需要在那個(gè)表里面建相應(yīng)的user。

 

  1. [root@:/usr/local/mongodb/bin]#./mongo    
  2.  
  3. MongoDB shell version: 1.8.2    
  4.  
  5. connecting to: test    
  6.  
  7. > use admin    
  8.  
  9. switched to db admin    
  10.  
  11. > db.auth('sa','sa')    
  12.  
  13. 1    
  14.  
  15. > use test    
  16.  
  17. switched to db test    
  18.  
  19. > db.addUser('test','test')    
  20.  
  21. {    
  22.  
  23. "user" : "test",    
  24.  
  25. "readOnly" : false,    
  26.  
  27. "pwd" : "a6de521abefc2fed4f5876855a3484f5"    
  28.  
  29. }    
  30.  
  31. >    

 

當(dāng)然必須有相關(guān)權(quán)限才可以建立。

再登錄看看:

 

  1. [root@:/usr/local/mongodb/bin]#./mongo    
  2.  
  3. MongoDB shell version: 1.8.2    
  4.  
  5. connecting to: test    
  6.  
  7. > show collections    
  8.  
  9. Fri Jul 22 14:45:08 uncaught exception: error: {    
  10.  
  11. "$err" : "unauthorized db:test lock type:-1 client:127.0.0.1",    
  12.  
  13. "code" : 10057    
  14.  
  15. }    
  16.  
  17. > db.auth('test','test')    
  18.  
  19. 1    
  20.  
  21. > show collections    
  22.  
  23. system.indexes    
  24.  
  25. system.users    
  26.  
  27. >    

 

 關(guān)于MongoDB權(quán)限管理就介紹到這里,希望能對各位有所幫助。

【編輯推薦】

  1. 淺談Oracle Buffer Cache的優(yōu)化思路
  2. 不同數(shù)據(jù)庫對blob字段的處理代碼演示
  3. RedHat Linux的Oracle 10g安裝配置詳解
  4. Oracle數(shù)據(jù)庫使用存儲過程創(chuàng)建自動增長列
  5. SQL Server數(shù)據(jù)庫回顧之存儲過程的創(chuàng)建和應(yīng)用
責(zé)任編輯:趙鵬 來源: CSDN博客
相關(guān)推薦

2022-06-24 08:48:47

用戶名密碼登錄

2009-08-18 13:52:57

Ubuntu用戶名密碼

2020-07-11 09:26:16

數(shù)據(jù)泄露黑客網(wǎng)絡(luò)攻擊

2014-09-11 09:25:19

2011-08-29 10:38:42

用LINQ去除重復(fù)菜單

2023-12-26 09:33:47

2010-05-31 09:10:20

Myeclipse S

2011-09-06 10:36:44

2010-05-24 14:00:43

Flex Svn

2013-05-29 09:47:45

2019-08-26 19:24:55

Podman容器Linux

2013-11-21 09:10:27

MongoDB

2009-10-21 17:13:32

Oracle用戶名

2009-06-18 15:05:11

2011-01-11 14:06:39

2010-09-27 14:48:12

SQL用戶名

2013-01-04 17:51:28

Android開發(fā)SharedPrefe解析用戶名

2009-10-26 16:08:40

Oracle默認(rèn)用戶名

2021-10-04 08:26:10

用戶名密碼信息

2019-11-12 09:23:16

Telnet密碼抓包
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號