The compat
mode in /etc/nsswitch.conf
represents a transitional method for user authentication that bridges traditional Unix authentication with modern directory services. This approach dates back to when systems were migrating from pure local authentication to network-based solutions like NIS and later LDAP.
When configured as:
passwd: files compat
passwd_compat: ldap
The system processes authentication in this sequence:
- First checks local
/etc/passwd
- Then processes entries marked with
+
in passwd file - Finally queries the LDAP directory for users in specified netgroups
Here's how to configure it:
# /etc/nsswitch.conf
passwd: files compat
passwd_compat: ldap
# /etc/passwd (sample entries)
root:x:0:0:root:/root:/bin/bash
+@ldapusers
While compat mode works, most modern systems prefer:
passwd: files sss
# or
passwd: files ldap
SSSD (System Security Services Daemon) provides better caching, offline authentication, and more flexible configuration options.
Some legacy scenarios where compat mode remains useful:
- Migration projects from NIS to LDAP
- Systems requiring specific netgroup-based access control
- Environments where other methods introduce compatibility issues
The compat mode has some limitations:
- No built-in caching of LDAP queries
- Simple bind operations can cause performance issues
- Limited flexibility in user attribute mapping
The /etc/nsswitch.conf
file is the backbone of Name Service Switch configuration in Linux systems, governing how various system databases (like passwd, shadow, and groups) are consulted. When dealing with LDAP user enumeration, administrators often face multiple configuration approaches.
The compat
mode in nsswitch provides a hybrid approach between traditional flat files and modern directory services:
# Basic compat configuration example
passwd: files compat
passwd_compat: ldap
This mode allows special entries in /etc/passwd
to trigger lookups in other services. The +
syntax enables netgroup expansions from LDAP:
# Example /etc/passwd entry
+@netgroup
The compat method was historically useful during transitions from local to LDAP authentication. However, modern systems prefer:
# Modern recommended approach
passwd: files sss ldap
Key limitations of compat mode include:
- Limited filtering capabilities compared to SSSD
- No advanced caching mechanisms
- Poor handling of nested netgroups
Here's a complete configuration example:
# /etc/nsswitch.conf
passwd: files compat
group: files compat
shadow: files compat
passwd_compat: ldap
group_compat: ldap
# /etc/passwd entry
+@ldapusers
Required LDAP client configuration:
# /etc/ldap.conf
uri ldap://ldap.example.com
base dc=example,dc=com
nss_base_passwd ou=People,dc=example,dc=com
Compat mode can cause performance issues in large environments due to:
- Sequential query processing
- Lack of result caching
- Network latency impact on every lookup
For enterprise environments, SSSD provides better performance through:
- Persistent connections
- Advanced caching
- Failover handling
Transitioning from compat mode to SSSD involves:
# New nsswitch.conf
passwd: files sss
group: files sss
shadow: files sss
# /etc/sssd/sssd.conf
[domain/example]
id_provider = ldap
auth_provider = ldap
ldap_uri = ldap://ldap.example.com
ldap_search_base = dc=example,dc=com