How to Apply Changes to nsswitch.conf Without Restarting Services


2 views

The /etc/nsswitch.conf file is a critical configuration file that determines how system databases (like passwd, groups, hosts) are accessed by applications. Unlike many other configuration files, modifications to nsswitch.conf don't require restarting any specific daemon.

Name Service Switch functionality is implemented through glibc's resolver library, not a standalone daemon. When applications make name service requests, they read nsswitch.conf dynamically through glibc. This means:

  • Changes take effect for new processes immediately
  • Existing processes continue using their loaded configuration

To ensure your changes take full effect:

# Example of testing nsswitch.conf changes
getent passwd username  # Tests user lookup
getent hosts example.com  # Tests host resolution

While not strictly necessary, restarting dependent services can help:

# Common services that might cache nsswitch.conf lookups
sudo systemctl restart sshd
sudo systemctl restart cron

After adding LDAP to your nsswitch.conf:

# Before: 
passwd: files 
# After:
passwd: files ldap

# Test with:
getent passwd ldapuser
# No restart needed, but ensure nscd is properly configured

The Name Service Cache Daemon (nscd) can complicate matters. If you're using it:

sudo systemctl restart nscd  # Clears cached entries

The /etc/nsswitch.conf file is a critical configuration file that determines the sources from which system databases (such as passwd, group, hosts) are obtained and their order of lookup. Unlike typical service configuration files, modifications to nsswitch.conf don't require restarting a dedicated "nss daemon" because of how the Name Service Switch (NSS) functionality is implemented in Linux/Unix systems.

The NSS functionality is implemented as part of the GNU C Library (glibc). When applications make system calls that require name service lookups (like getpwnam() or gethostbyname()), the glibc implementation reads nsswitch.conf directly:

#include 
#include 

int main() {
    // Example of how glibc checks nsswitch.conf internally
    __nss_configure_lookup("passwd", "files ldap");
    printf("NSS configuration updated\n");
    return 0;
}

Changes to nsswitch.conf take effect:

  • Immediately for new processes
  • After process restart for existing processes
  • No system-wide daemon restart is needed

Here's what happens with different types of processes after modifying nsswitch.conf:

# Example showing immediate effect on new processes
$ cat /etc/nsswitch.conf | grep hosts
hosts:      files mdns4_minimal [NOTFOUND=return] dns

# After modification
$ sed -i 's/mdns4_minimal/mdns4/' /etc/nsswitch.conf

# New process sees changes immediately
$ getent hosts example.com

While most services will pick up changes automatically, some long-running daemons might need to be restarted:

  • SSH daemon (sshd) - maintains cached connections
  • Database servers - often cache user authentication
  • Web servers with persistent connections

For these services, you might need to run:

sudo systemctl restart sshd
sudo systemctl restart postgresql

To test if your changes are effective:

# Check the current configuration
$ getent -s files,ldap passwd username

# Trace NSS lookups (useful for debugging)
$ strace -e openat getent passwd root 2>&1 | grep nsswitch

For systems where you can't easily restart services, you can force glibc to reload its configuration:

# For testing purposes only (not recommended for production)
$ kill -USR1 $(pidof some_long_running_process)