Skip to content

Instantly share code, notes, and snippets.

@afonsoaugusto
Created January 10, 2018 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afonsoaugusto/64da35d1f05ee3e17f43ca40453c7a55 to your computer and use it in GitHub Desktop.
Save afonsoaugusto/64da35d1f05ee3e17f43ca40453c7a55 to your computer and use it in GitHub Desktop.
use admin
db.createUser(
{
user: "alice",
pwd: "secret",
roles: [ { role: "root", db: "admin" } ]
}
)
sudo mongod --auth --port 27017 --dbpath=/var/lib/mongodb
sudo mongod --auth --port 27017 --dbpath=/var/lib/mongodb --config=/etc/mongod.conf
mongod --auth --port 27017 --dbpath /data/db1
mongo --port 27017 -u "alice" -p "secret" --authenticationDatabase "admin"
> db.runCommand({getParameter: 1, authenticationMechanisms: 1})
{
"ok" : 0,
"errmsg" : "getParameter may only be run against the admin database.",
"code" : 13,
"codeName" : "Unauthorized"
}
> use admin
switched to db admin
> db.runCommand({getParameter: 1, authenticationMechanisms: 1})
{
"authenticationMechanisms" : [
"MONGODB-CR",
"MONGODB-X509",
"SCRAM-SHA-1"
],
"ok" : 1
}
mongo -u alice -p secret --eval "db.runCommand({getParameter: 1, authenticationMechanisms: 1})" --authenticationDatabase admin
db.runCommand({getParameter: 1, authenticationMechanisms: 1})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment