Your Search Bar For Shrewd Tips

How Do I Clear Ldap Cache In Linux?


When a Linux system keeps showing old LDAP user or group information, the cause is often a local cache rather than the LDAP server itself. The right way to clear it depends on which service your computer uses: SSSD, NSCD, or another LDAP client. Restarting the wrong service may have no effect, while deleting cache files manually can cause login or directory lookup problems. This guide explains how to identify the cache, clear it safely, and confirm that Linux is seeing current LDAP data.

What Does the LDAP Cache Store?

Linux systems commonly use LDAP to look up account details such as usernames, user IDs (UIDs), group IDs (GIDs), group membership, and home directories. To avoid contacting the LDAP server for every lookup, a local service may temporarily store some of these results. This is useful for performance and can help users continue working during a short network interruption.

That local cache can also explain why a change made in LDAP does not appear immediately. A recently changed group membership, for example, may still be represented by an older cached result. The cache is on the Linux client; clearing it does not erase or modify the account in the LDAP directory.

There is no single command that clears every LDAP-related cache on every Linux distribution. First find out which service handles identity lookups on your system.

Identify Which Service Handles LDAP Lookups

Check the status of the common services with systemd:

  • systemctl status sssd checks whether SSSD is running.
  • systemctl status nscd checks whether the Name Service Cache Daemon is running.
  • systemctl status nslcd checks whether the LDAP Name Service Daemon is running.

You can also inspect the configured name-service sources in /etc/nsswitch.conf. Look at entries such as passwd:, group:, and shadow:. An entry containing sss commonly indicates SSSD; one containing ldap may indicate an LDAP NSS module or NSLCD. An nscd service may cache lookups regardless of which source provides them.

Service names and configuration vary by distribution. If a command reports that a unit is not found, that service may not be installed, may use a different unit name, or may not be responsible for your LDAP lookups.

Clear the SSSD Cache

SSSD (System Security Services Daemon) is widely used for LDAP and Active Directory identity management. If SSSD is handling your lookups, use its tools to expire cached data rather than deleting its database files manually.

To expire all cached SSSD entries, run:

sudo sss_cache -E

Then check a user or group again. If needed, restart SSSD so the service reconnects and refreshes its state:

sudo systemctl restart sssd

To expire data for one user instead of clearing the entire cache, use:

sudo sss_cache -u username

Replace username with the account’s login name. To expire a particular group, use:

sudo sss_cache -g groupname

Some SSSD versions provide equivalent cache-expiration commands through sssctl. For example, sudo sssctl cache-expire -E expires all entries, while options can target a specific user or group. Check the installed version’s help with sssctl cache-expire --help if an option is unavailable.

Expiration tells SSSD that stored information needs to be refreshed; it does not necessarily remove every item from disk immediately. SSSD may retain data for offline authentication or other configured features. Avoid removing files from /var/lib/sss/db/ while SSSD is running. If a full cache reset is necessary, follow the procedure for your distribution and SSSD version, and plan for a temporary loss of cached/offline identity information.

Clear the NSCD Cache

NSCD, the Name Service Cache Daemon, can cache password, group, and other name-service lookups. If NSCD is active, invalidate the relevant database with nscd. To clear cached user and group information, run:

sudo nscd -i passwd

sudo nscd -i group

To invalidate all databases supported by the running NSCD configuration, use:

sudo nscd -i hosts

Repeat that command for other databases you need to refresh, such as services or netgroup, if they are configured and relevant. The hosts database concerns name resolution for machines; it is not the same as LDAP user and group data.

On some systems, restarting NSCD is a straightforward way to discard its in-memory cache:

sudo systemctl restart nscd

Use targeted invalidation when possible, especially on a busy server. Restarting a name-service daemon can briefly interrupt lookups, and invalidating one database is usually sufficient for a user or group change.

What If the System Uses NSLCD or nslcd?

NSLCD, commonly provided by the nslcd service, connects NSS and PAM requests to an LDAP server. It is not generally a persistent identity cache in the same way as SSSD. If the system uses NSLCD, first check whether NSCD is also running; NSCD may be the component retaining old user or group lookups.

Restarting NSLCD can refresh its connection to LDAP, but it should not be treated as a guaranteed cache-clear command:

sudo systemctl restart nslcd

If NSCD is active, invalidate its passwd and group databases as described above. If results remain stale, inspect the LDAP client configuration and logs rather than repeatedly restarting services. On a system without systemd, use the service-management command supplied by that distribution.

Check That the New LDAP Information Is Visible

After clearing the relevant cache, query the account through the system’s normal name-service interface. This checks what applications using NSS are likely to see:

getent passwd username

getent group groupname

To check a user’s effective group membership, run:

id username

Use the exact account and group names, and compare the output with the expected UID, GID, and memberships. If the result still appears old, confirm that the change was saved in LDAP and that the client can reach the correct directory server.

For a separate check that bypasses the usual NSS lookup path, an administrator can query LDAP directly with ldapsearch. The exact command depends on the directory’s base distinguished name, authentication method, and TLS settings. For example, a simple query may look like this:

ldapsearch -LLL -x -H ldaps://ldap.example.com -b "dc=example,dc=com" "(uid=username)"

Use your organization’s approved server and security settings; do not put passwords directly into shell commands, where they may be saved in shell history or exposed in process listings. If ldapsearch returns the updated entry but getent does not, the issue is likely in the client-side lookup or cache path. If the direct query also returns old information, investigate the directory server, replication, or the LDAP entry itself.

Common Problems and Safety Tips

  • Clearing the wrong cache: Restarting NSCD will not clear SSSD’s cache, and expiring SSSD entries will not necessarily invalidate NSCD data. Identify all active lookup services before troubleshooting.
  • Only one field remains stale: User details and group membership may be cached or resolved separately. Check both passwd and group data, then test with id.
  • Changes take time to propagate: LDAP replication between directory servers can delay updates. A client may contact a replica that has not received the change yet.
  • Offline access is configured: SSSD may keep cached credentials or identity information to support offline use. Expiring identity entries is not necessarily the same as deleting offline authentication data.
  • Manual deletion causes trouble: Do not remove cache databases or lock files by hand unless your distribution’s documentation specifically instructs you to do so and the relevant service is stopped.
  • Commands require privileges: Cache invalidation and service restarts generally need sudo. Use the smallest action that solves the problem, particularly on production servers.

When troubleshooting a login issue, be cautious about restarting identity services on a remote machine. Existing sessions may remain open, but new logins or commands that need directory lookups could be affected if the service cannot reconnect. Make sure you have an alternate administrative access method before making changes on a critical system.

Conclusion

To clear an LDAP cache in Linux, first identify which component is serving identity lookups. For SSSD, use sudo sss_cache -E or expire a specific user or group; for NSCD, invalidate the relevant database with nscd -i passwd and nscd -i group. If the system uses NSLCD, check whether NSCD is caching results, since restarting nslcd alone may not clear a separate cache.

Finally, verify the result with getent or id, and use an LDAP query to distinguish a client-cache problem from a directory or replication issue. Prefer supported cache tools over manual deletion, and avoid broad service restarts unless targeted invalidation does not work.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →