Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ mongo
- MongoDB shell version v3.4.3
- connecting to: mongodb://127.0.0.1:27017
- MongoDB server version: 3.4.3
- > use admin
- switched to db admin
- > db.createUser( {user:"mongo", pwd:"mongo", roles:["root"]} )
- Successfully added user: { "user" : "mongo", "roles" : [ "root" ] }
- > db.getUser("mongo")
- {
- "_id" : "admin.mongo",
- "user" : "mongo",
- "db" : "admin",
- "roles" : [
- {
- "role" : "root",
- "db" : "admin"
- }
- ]
- }
- > db.auth("mongo","mongo")
- 1
- $ grep -A 1 security /etc/mongod.conf
- #security:
- # authorization: enabled
- $ ps aux | grep mongo
- mongodb 12583 0.5 3.4 2381948 281140 ? Sl 18:34 0:06 /usr/bin/mongod --config /etc/mongodb.conf
- $ grep auth /etc/mongodb.conf
- #noauth = true
- auth = true
- $ /etc/init.d/mongodb restart
- $ mongo -u mongo -p --authenticationDatabase admin
- MongoDB shell version v3.4.3
- Enter password: **********
- connecting to: mongodb://127.0.0.1:27017
- MongoDB server version: 3.4.3
- > show dbs
- admin 0.078GB
- android 0.078GB
- blog 0.078GB
- games 0.078GB
- school 0.078GB
- $ mongo
- MongoDB shell version v3.4.3
- connecting to: mongodb://127.0.0.1:27017
- MongoDB server version: 3.4.3
- > show dbs
- 2017-10-03T19:04:55.953+0000 E QUERY [thread1] Error: listDatabases failed:{
- "ok" : 0,
- "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
- "code" : 13,
- "codeName" : "Unauthorized"
- } :
- _getErrorWithCode@src/mongo/shell/utils.js:25:13
- Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
- shellHelper.show@src/mongo/shell/utils.js:761:19
- shellHelper@src/mongo/shell/utils.js:651:15
- @(shellhelp2):1:1
- >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement