Moodle LDAP and Active Directory authentication and user sync

Moodle's core LDAP plugin can sign users in against Active Directory or OpenLDAP and keep accounts in step with the directory. This page covers the design decisions, setup sequence, security controls and limits to confirm before go-live.

On this page

When Moodle LDAP authentication fits and what it covers

The Moodle LDAP plugin checks a user's password against an Active Directory or OpenLDAP directory and keeps the Moodle user record in step with the directory. Choose it when staff and learners already hold their credentials in a directory, when your network is built around that directory, and when you need Moodle to read directory attributes on every sync. Choose a SAML2 or OAuth 2 plugin instead when the sign-in must go through a cloud identity provider, when federation partners need to sign in without a directory account, or when the directory is not reachable from the web server. The plugin ships in Moodle core under public/auth/ldap, so it is maintained with the rest of the platform and needs no third-party code. This page covers that core LDAP path only.

The plugin does more than check passwords. It can create accounts when a user first signs in, update profile fields from directory attributes, and run a scheduled user sync task that suspends accounts whose directory entries have been removed or disabled. Each of these behaviours is controlled by settings you choose before go-live, so the decisions about bind credentials, search contexts, which attributes map to which Moodle fields, and whether Moodle may write to the directory belong in the design phase. Confirm with your directory team which object classes and attributes hold the people you want in Moodle, because a wrong search context or a missing attribute is the most common reason a sync appears to work but silently misses users.

Writing to the directory is the part that changes the risk profile. Creating accounts in Active Directory from Moodle requires an LDAPS connection and a bind user with adequate rights, so the directory team must approve that account and its permissions before you plan this feature. If your organization only needs Moodle to read the directory, a read-only bind account is the simpler position to defend. Ask your directory and security teams to confirm which option applies, and record the decision, because it determines the certificate work, the privileges on the bind account and what an auditor will expect to see.

How sign-in and the user sync task reach the directory

Sign-in starts in a browser request to Moodle's web server, which uses the LDAP authentication plugin to bind to the directory over LDAPS with a dedicated bind user. The scheduled user sync task makes the same bind from cron, searches the configured contexts and writes matched accounts into the Moodle user table. Check that every hop to the directory is encrypted, that the bind user has only the rights it needs, and that the search contexts cover only the OUs you intend to sync.

Sign-in and cron sync both reach the directory through one LDAPS bind and search path.

Which LDAP plugin options fit which directory design

This table compares the main auth_ldap settings for Active Directory and OpenLDAP designs, from bind accounts and transport to sync and removed-user handling. Read each row against your directory layout first, then check the option that matches your design. The main takeaway is that account creation from Moodle and removed-user handling carry the most risk and need a written decision before go-live.

OptionWhat it controlsWhen it fits
Bind user and contextsThe service account Moodle uses to search the directory, and the container paths where it looks for usersUse a least-privilege read account scoped to the OUs that hold learners and staff. Choose a broader scope only when those OUs are not separated.
User typeThe attribute conventions Moodle uses for usernames, object classes and account stateSelect the Active Directory convention for AD forests and the OpenLDAP convention for directories that use posixAccount-style schemas. Confirm the exact fields in your schema.
LDAPSEncrypted LDAP over TLS on the standard secure port, with the server certificate validated by Moodle's hostPreferred for any production bind, and required when Moodle creates accounts in AD. Confirm the CA chain is trusted by the Moodle server.
StartTLSUpgrades a plain LDAP connection to TLS on the same portUse only where the directory does not offer LDAPS. Confirm the server supports StartTLS and that the connection is validated, not just negotiated.
Field mappingWhich directory attributes populate Moodle profile fields such as first name, last name, email and ID numberMap to attributes that are unique, stable and maintained by HR or the directory team. Avoid mutable fields as the matching key.
Sync task and scopeHow often Moodle reconciles accounts with the directory and which records it considersSchedule runs around peak course activity and confirm the task runs under cron. Limit the search scope so disabled or out-of-scope accounts are handled predictably.
Removed-user handling (suspend)Marks accounts as suspended when they no longer match the directory, keeping history and course records intactFits most regulated sites, where records must be retained and reactivation may be needed. Confirm how the suspended state interacts with your retention policy.
Removed-user handling (delete)Removes Moodle accounts that no longer exist in the directory, along with their associated dataOnly fits where a documented retention and deletion process exists and has been approved. Deletion is hard to reverse, so test on a copy first.
Account creation from MoodleLets Moodle create new accounts in Active Directory from its own forms or sign-up flowFits few designs. It needs LDAPS and a bind account with rights to create objects in the target OU, which is a privileged permission that security teams usually review closely.

How to set up LDAP sync in Moodle step by step

This sequence takes a Moodle site from a directory request to a scheduled user sync with a documented removed-user policy. Each step closes with a check, so problems surface on a test account before any live user is affected.

  1. Confirm directory and service account details

    Agree the directory type, domain controller or LDAP host names, the base contexts that hold staff and student accounts, and the bind account with the directory team. Ask for a read-only bind account scoped to those contexts, and record which account attributes will hold the username, email, first name, last name and any ID number. If the sync must create accounts in Active Directory, confirm that the bind account has the rights to do so and that the connection will use LDAPS, because Moodle's LDAP language strings state that creating new accounts in Active Directory requires an LDAPS connection and a bind user with adequate rights. Done when the directory team has written down these values and confirmed them in a test query from a separate client.

  2. Establish LDAPS certificate trust on Moodle servers

    Obtain the certificate chain for the directory's LDAPS endpoint from the directory team and install it in the trust store used by the PHP process on every Moodle web node and on the server that runs cron. Confirm the host name in the certificate matches the name Moodle will connect to. Check the trust from the command line using the same client libraries PHP uses, since a server that trusts the certificate for a browser may still reject it for the LDAP client. Done when a test LDAPS bind succeeds from each Moodle server, including the cron host.

  3. Enable the plugin and enter bind and context settings

    As a site administrator, enable the LDAP server authentication plugin from the authentication settings in Moodle. Enter the host URL using the ldaps scheme, the bind user distinguished name and password, and the contexts that hold user objects. Set the user search attribute and the object class that matches your directory. Keep the bind password in the site settings only for the minimum period needed, and restrict who can view the authentication settings page. Done when the plugin's connection test reports a successful bind and returns the expected user entries for a known account.

  4. Test a single sign-in with a pilot account

    Choose one test account in the directory that belongs to a named pilot user and has a known role. Sign in to Moodle with that account from a browser on a normal network path, and confirm that the account is created or matched to the correct Moodle user record. Check that the username, email and name fields look correct on the profile and that the account is not granted administrator rights it should not hold. Done when the pilot sign-in works, the profile is correct, and the sign-in is recorded in the site logs.

  5. Map directory fields to Moodle profile fields

    Review the field mapping in the plugin settings and map each Moodle profile field to the directory attribute agreed in step one. Lock fields that Moodle should only read from the directory, so users cannot overwrite them in their profile, and leave locally managed fields unlocked where the business needs them. Decide which fields are updated on every sign-in and which only on account creation. Done when the pilot account's profile after a second sign-in shows the mapped values, and a change made to a test attribute in the directory appears in Moodle after the next sync.

  6. Run the user sync task manually and review logs

    Run the LDAP user sync task by hand from the scheduled tasks page, with the site in a quiet period and a backup taken beforehand. Review the task output and the site logs for accounts created, updated, suspended and any errors such as failed searches or missing mandatory fields. Compare the counts with the expected number of matching directory entries and investigate any gap before continuing. Done when the output matches the expected counts for a sample group and no unexplained errors remain.

  7. Schedule the sync and document the removed-user policy

    Set the sync task schedule in the scheduled tasks page at a frequency agreed with the directory and HR owners, and confirm that the cron host runs it under the expected account. Write down the removed-user policy: whether accounts that disappear from the directory are suspended or deleted, how long suspended accounts are kept, who approves exceptions, and how the policy is tested. Confirm the setting that controls removal behaviour in the plugin configuration matches the written policy. Done when the scheduled task shows a successful next run, and the signed policy is stored with the site runbook.

Active Directory or OpenLDAP: how the design changes

Active Directory is the most common directory in organizations that run Moodle alongside Windows infrastructure, and it carries account controls that Moodle's LDAP plugin can read and, in some cases, write. User state is held in attributes such as the account control flags on the user object, so suspending a departed user can mean disabling the AD account and letting the next sync reflect that in Moodle. Creating accounts from Moodle into AD is possible, but the plugin needs an LDAPS connection and a bind user with adequate rights, and the directory itself will refuse writes that are not encrypted.

  • Bind user rights: Plan a dedicated service account with only the delegated permissions needed to read the user container and, if account creation is in scope, to create and modify user objects in one organizational unit. Confirm the exact rights with your directory team before granting them.
  • LDAPS for account creation: Account creation from Moodle requires an LDAPS connection, so certificate trust and the Moodle server's CA store must be settled before any write is configured.
  • Account control for suspension: Decide whether suspension means disabling the AD account or only flagging it in Moodle. Disabling in AD is visible to every system that authenticates against the directory, so it needs an explicit approval step.
  • Field mapping: Map identifiers such as the user principal name or sAMAccountName deliberately, because changing the match key later reassigns or duplicates accounts.
  • Contexts and nested groups: Limit the user contexts to the OUs Moodle should see, since broad search roots slow sync and pull in service and disabled accounts.

Check that your directory team can state the exact delegated rights and certificate chain before a single write is tested.

Securing the bind account, LDAPS and account creation

The LDAP plugin holds a directory credential and, if you allow it, can write new accounts into Active Directory. Each card below covers one control that limits what that credential can reach, how it is transported and stored, and who can change the settings that use it.

Least-privilege bind user

The bind user is the account Moodle uses to search the directory and read user attributes. Give it read access only to the OUs that hold users Moodle needs, and no membership in administrative groups. Ask your directory team to confirm which attributes it can read, and test the bind with a non-admin account before go-live. Document who owns the account and when its password rotates, because a sync stops silently when that password expires.

LDAPS and certificate trust

Plain LDAP sends the bind password and user data across the network unencrypted. Use LDAPS, and make sure the PHP and web server on the Moodle host trust the certificate chain of the domain controller or the CA that issued it. Test the connection from the Moodle server itself, not from your workstation, because the trust store on the server is what counts. Confirm which domain controllers are listed and that certificate renewal is covered by someone's calendar.

Rights needed to create AD accounts

Creating accounts in Active Directory from Moodle requires an LDAPS connection and a bind user with adequate rights, which is a material step up from read-only sync. Such a bind user can create and modify objects in the target OU, so an error or compromise of Moodle can change directory data. Scope the rights to one provisioning OU, grant only the attributes and control needed, and ask your security team to review that the account cannot touch privileged groups.

LDAP plugin strings

Passwords and directory credentials in Moodle

Decide whether Moodle stores user passwords at all. With LDAP authentication, users should authenticate against the directory and Moodle should not keep a copy of their credentials. The bind password is still stored in the plugin configuration, so restrict database and backup access to it, and review whether database backups or support exports contain it. Check that the bind password is not written to logs or shown in configuration exports.

Restricting who changes plugin settings

Changes to server, bind, search filter and field mapping settings alter who can sign in and which directory objects Moodle may touch. Limit the site administrator role to a named group, require change tickets for authentication settings, and confirm that delegated roles cannot edit auth_ldap configuration. Review the list of site administrators on a set schedule, since a single added administrator can redirect the whole sync.

Logging and monitoring sync runs

The user sync task is the control point for suspensions and account creation, so a failed or unexpected run should be visible. Review the scheduled task logs and the Moodle logs for failed binds, unusual creation counts and mass suspensions after each change. Alert on a run that fails repeatedly or suspends more accounts than normal, and confirm with your directory team how those alerts reach an owner outside the Moodle administrators.

How suspending removed users and sync timing affect access

The LDAP sync task decides what happens to a Moodle account when its directory entry disappears or is disabled, so set that behavior deliberately before go-live. In the auth_ldap settings, removed or disabled directory accounts are normally suspended in Moodle rather than deleted. Suspension blocks sign-in while keeping the user record, enrolments, submissions and grades intact, which is what most institutions want because gradebook history and audit trails depend on those records. Deletion removes the account and its associated data, and that step is hard to reverse from the sync task alone. Confirm the exact options and their defaults in the Moodle version you run, because the sync settings and the handling of attributes such as the suspended flag have changed between releases. Check the auth_ldap language strings and the release notes for your version rather than relying on memory of an older site.

Write a removal policy before the first full sync. It should state who is suspended when a directory account is disabled, how long a suspended account is kept, who may request deletion, and how grades and files are handled for leavers, students who withdraw and contractors whose contracts end. Map each directory state (disabled, moved out of the synced container, deleted) to a Moodle outcome, and agree that outcome with the registrar or HR owner. Note that a student who is moved out of the synced OU will be treated as removed, so a directory reorganization can suspend a whole cohort during term. Ask your directory team to confirm how deprovisioning is recorded in AD before relying on it.

Test with a sample account before trusting the policy. Create a dedicated test user in a test OU, enrol it in a course with a graded activity, then disable it in AD and run the sync task manually. Verify that the Moodle account is suspended, that sign-in fails, that the enrolment and grade records remain, and that re-enabling the account restores access without creating a duplicate. Repeat the test with the account moved out of the synced container. Sync frequency and directory size both load cron: a full scan of a large directory on every run takes longer and competes with other scheduled tasks, so confirm the schedule for the LDAP sync task against your user count and cron capacity, and monitor run times after each change.

Limits to confirm in your environment before go-live

Several limits in an LDAP or Active Directory integration depend on your Moodle release, your directory schema and your account-creation rules, not on general guidance. The cards below list what to confirm with your platform team and the directory owner before a go-live date is set.

Moodle version, PHP and database

Confirm the target release before anything else, because the requirements change between versions. For Moodle 5.1, the server needs 64-bit PHP 8.2 or later (8.3 and 8.4 are supported), a supported database such as PostgreSQL 15 or MySQL 8.4, and a site already on Moodle 4.2.3 or later to upgrade. Check that your web server document root points to the /public directory, otherwise the site may show directory listings or errors.

Moodle 5.1 notes

LDAP plugin fields against your schema

The LDAP plugin maps Moodle fields to directory attributes, and those attribute names must match what your directory actually holds. Check the user object class, the username attribute, the contexts searched and the attributes used for names and email in your Active Directory or OpenLDAP schema. Test the mapping with a few real accounts in a non-production site before enabling the sync task.

Account creation requires LDAPS and rights

Creating new accounts in Active Directory from Moodle requires an LDAPS connection and a bind user with adequate rights. Confirm with the directory owner that the bind account can create and modify user objects only in the intended container, and that the certificate chain is trusted by the Moodle server. Without both, account creation will fail or the bind credentials will travel unprotected.

NTLM SSO is a separate setup

Transparent sign-in for domain-joined Windows machines is a separate option in the LDAP plugin and is not switched on by the basic bind and sync configuration. It depends on web server modules, browser trust settings and the domain's authentication setup. Confirm these with your web team and the directory owner, and consider whether SAML or OAuth 2 sign-in fits better for your users.

Account creation behavior with the directory owner

Agree in writing who may create accounts, which container they land in, which attributes they receive and how removed users are suspended rather than deleted. Confirm whether the directory team expects Moodle to write to AD at all, since that choice affects audit logs, password policy and offboarding. A decision recorded with the owner avoids disputes after the first sync run.

Questions buyers ask about Moodle LDAP and AD sync

What does a Moodle LDAP or Active Directory integration cost, and what drives the effort?

The cost depends on the size and shape of the directory, not on a fixed price list. The main drivers are the number of organizational units and contexts Moodle must search, whether nested groups and multiple domains are involved, how much field mapping is needed, and how much certificate work LDAPS requires. Testing against realistic accounts, including suspensions and renamed users, adds effort, as does a staged rollout to pilot cohorts. Ask for a quote that lists each of these as a separate line, states which environments are covered (test, staging, production), and says whether the directory team or the client's own staff will perform the AD-side changes. DeployOpen does not publish prices; a quote follows from the written scope.

How long does an LDAP or AD sync setup take to deliver?

Duration is set by the number of unknowns that must be resolved before configuration starts. Access approvals for a bind account, certificate issuance for LDAPS, agreement on which attributes map to Moodle profile fields, and the number of contexts to sync all add time, and most of these depend on the client's internal change process rather than on the Moodle work itself. Testing against a copy of the real directory structure and a pilot group before production sync is a common reason schedules extend. Ask for a timeline in the written scope that names each dependency, who owns it, and what is needed from the client at each milestone.

What does the client need to provide before work starts?

The engagement needs a few specific items from the directory and infrastructure owners. These typically include:

  • A read-only bind user with rights to search the required contexts and read the attributes Moodle will map
  • A service account with enough rights to create or modify accounts only if Moodle should create users in AD
  • A certificate for LDAPS that the Moodle server trusts, issued by a CA the client already operates
  • A set of test accounts in each relevant organizational unit, including accounts that can be suspended safely
  • Documentation of which attributes identify a person and which change over time

Confirm these with the directory team early, because certificate and privilege approvals are usually the longest items.

Can an internal team set up Moodle LDAP sync without a partner?

Yes, an experienced internal team can configure the core LDAP authentication plugin and its user sync task, provided it has Moodle administration skills, directory administration access and the ability to test and roll back changes. The work becomes harder where the team has not run LDAPS before, where the directory has multiple domains or deep nesting, or where account creation from Moodle into AD is required, since that changes the security boundary. A partner is most useful for fixed-scope design, security review of the bind account and rights, and a documented test plan. Decide based on who will own the configuration after go-live and who will handle the next Moodle upgrade.

Should we use LDAP or SAML2 for Moodle sign-in?

LDAP authentication lets Moodle check a username and password against the directory, which suits sites that want direct directory integration and already run AD or OpenLDAP. SAML 2.0 hands the sign-in to an identity provider through the SAML2 Single sign on plugin (auth_saml2), which is maintained by Catalyst IT and lists support for Moodle 2.7 through 5.1, and it is often preferred where the organization already runs a federated identity provider with multi-factor authentication. Choosing LDAP means Moodle handles password checks and needs LDAPS and a bind account; choosing SAML2 moves that trust to the identity provider. Confirm which plugin version supports your target Moodle release before committing.

What happens to course data when a user is removed from the directory?

When the sync task finds that a user no longer exists in the directory, the usual configured behavior is to suspend the Moodle account rather than delete it, which keeps the user's grades, submissions and course history intact. Enrolments tied to that account remain in place until other processes change them, so you should confirm how enrolment sources interact with suspension and whether course memberships need separate cleanup. Ask the implementer to document the exact removal behavior, test it with a disposable account, and agree a retention and deletion policy with the records team before the first production run.

What does an LDAP sync need for security and certificates?

Credentials for the bind user should be stored and rotated under the client's normal secrets policy, and the bind account should have the narrowest read rights that the sync requires. LDAPS is the expected transport for any connection that carries credentials, so the Moodle server must trust the directory's certificate chain and the certificate must match the hostname Moodle uses. Confirm with your security team how these items are logged and reviewed, and whether account creation from Moodle into AD is permitted at all.

How DeployOpen scopes and delivers Moodle directory sync

DeployOpen plans, builds, documents and supports Moodle directory sign-in and user sync inside your own infrastructure, so your identity team can review each setting before it reaches production. Work starts from a written scope that names the directory, the account rules and the sync behavior your organization has approved.

How we scope

  • Inventory the directory forest, domains, OUs and the accounts Moodle must read or create.
  • Agree the bind user, its rights and the LDAPS certificate chain before any configuration begins.
  • Write down field mapping, suspension rules and account creation as signed-off decisions in the written scope.

How we build

  • Configure the LDAP authentication plugin and test LDAPS connections against a non-production Moodle site first.
  • Set the user sync task so removed or disabled directory accounts are suspended in Moodle, and verify with test accounts.
  • Test account creation in Active Directory from Moodle under the least-privilege bind user your team approves.

How we hand over

  • Deliver the configuration record, field mapping table, bind user permissions and certificate renewal steps as documentation.
  • Walk your identity and Moodle administrators through sync logs, failed-login checks and how to roll back a bad run.
  • Provide a test plan and results so your team can repeat the checks after future Moodle upgrades.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after handover.
  • Retainers can cover Moodle point releases, directory changes and retesting of sync behavior after each change.
  • Ask any provider to confirm response terms, change control and who holds administrator credentials in writing.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.