SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $ mongo
  2. MongoDB shell version v3.4.3
  3. connecting to: mongodb://127.0.0.1:27017
  4. MongoDB server version: 3.4.3
  5.    
  6. > use admin
  7. switched to db admin
  8. > db.createUser( {user:"mongo", pwd:"mongo", roles:["root"]} )
  9. Successfully added user: { "user" : "mongo", "roles" : [ "root" ] }
  10.    
  11. > db.getUser("mongo")
  12. {
  13.     "_id" : "admin.mongo",
  14.     "user" : "mongo",
  15.     "db" : "admin",
  16.     "roles" : [
  17.         {
  18.             "role" : "root",
  19.             "db" : "admin"
  20.         }
  21.     ]
  22. }
  23.  
  24. > db.auth("mongo","mongo")
  25. 1
  26.    
  27. $ grep -A 1 security /etc/mongod.conf
  28. #security:
  29. #  authorization: enabled
  30.    
  31. $ ps aux | grep mongo
  32. mongodb  12583  0.5  3.4 2381948 281140 ?  Sl  18:34  0:06 /usr/bin/mongod --config /etc/mongodb.conf
  33.    
  34. $ grep auth /etc/mongodb.conf
  35. #noauth = true
  36. auth = true
  37.    
  38. $ /etc/init.d/mongodb restart
  39.    
  40. $ mongo -u mongo -p --authenticationDatabase admin
  41. MongoDB shell version v3.4.3
  42. Enter password: **********
  43. connecting to: mongodb://127.0.0.1:27017
  44. MongoDB server version: 3.4.3
  45. > show dbs
  46. admin     0.078GB
  47. android   0.078GB
  48. blog      0.078GB
  49. games     0.078GB
  50. school    0.078GB
  51.    
  52. $ mongo
  53. MongoDB shell version v3.4.3
  54. connecting to: mongodb://127.0.0.1:27017
  55. MongoDB server version: 3.4.3
  56. > show dbs
  57. 2017-10-03T19:04:55.953+0000 E QUERY    [thread1] Error: listDatabases failed:{
  58. "ok" : 0,
  59. "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
  60. "code" : 13,
  61. "codeName" : "Unauthorized"
  62. } :
  63. _getErrorWithCode@src/mongo/shell/utils.js:25:13
  64. Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
  65. shellHelper.show@src/mongo/shell/utils.js:761:19
  66. shellHelper@src/mongo/shell/utils.js:651:15
  67. @(shellhelp2):1:1
  68. >
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top