- Security >
- Security Tutorials >
- Access Control Tutorials >
- Enable Authentication
Enable Authentication¶
On this page
Enable authentication using the auth
or keyFile
settings. Use auth
for standalone instances, and
keyFile
with replica sets and
sharded clusters. keyFile
implies
auth
and allows members of a MongoDB deployment to
authenticate internally.
Authentication requires at least one administrator user in the
admin
database. You can create the user before enabling
authentication or after enabling authentication.
Procedures¶
You can enable authentication using either of the following procedures:
Create the Administrator Credentials and then Enable Authentication¶
Enable Authentication and then Create Administrator¶
- Start the
mongod
ormongos
instance with theauth
orkeyFile
setting. - Connect to the instance on the same system so that you can authenticate using the localhost exception.
- Create the administrator user as described in Create a User Administrator.
Query Authenticated Users¶
If you have the userAdmin
or
userAdminAnyDatabase
role on a database, you can query
authenticated users in that database with the following operation: