Skip to content

Instantly share code, notes, and snippets.

@halilim
Last active August 29, 2015 14:13
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 halilim/263206929b44d4df1669 to your computer and use it in GitHub Desktop.
Save halilim/263206929b44d4df1669 to your computer and use it in GitHub Desktop.
Set Up MongoDB (2.6 and 3) Authentication

Set Up MongoDB (2.6 and 3) Authentication

  1. Create admin user

    use admin
    db.createUser(
        {
            user: "admin",
            pwd: "***",
            roles: [
                { role: "userAdminAnyDatabase", db: "admin" },
                "clusterAdmin" // For db.serverStatus()
            ]
        }
    )
  2. Enable auth (and disable bind 127... if needed) in /etc/mongod.conf

  3. Add user

    mongo -u admin -p --authenticationDatabase admin
    use db
    db.createUser(
        {
          user: "user",
          pwd: "***",
          roles: [
             { role: "dbOwner", db: "db" }
          ]
        }
    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment