Course contentsShow
← Linux
Lesson 838 of 1,8198. User Management and Pluggable Authentication ModulesFree lesson

Introduction to NSSwitch and Identity Lookups

You will configure the Name Service Switch to prioritize local vs remote identity resolution.

In this lesson, you will learn how to configure the Name Service Switch (NSS) to define the order in which your system searches for user and group identities.

The Role of NSSwitch

When you run a command like id username or ls -l, your system needs to map a name to a UID or GID. However, this information doesn't always live in just one place. It might be stored locally in /etc/passwd and /etc/group, or it might exist on a remote server like LDAP, SSSD, or NIS.

The nsswitch.conf file acts as the "traffic controller" for these requests. It tells the operating system where to look first, second, and third, and what to do if a source is unreachable.

Configuring Priority

The configuration file is located at /etc/nsswitch.conf. Each line represents a database (like passwd, group, or hosts) followed by a list of sources.

Consider this standard configuration for user lookups:

passwd: files systemd
group:  files systemd

In this example, the system first checks files (the local /etc/passwd file). If the user is found, the lookup stops there. If not, it moves to systemd (which handles dynamic users).

If you were integrating a remote identity provider, you might change the configuration to look like this:

passwd: files sssd
group:  files sssd

By placing files before sssd, you ensure that local administrative accounts (like root or admin) are always resolved immediately from the local disk, preventing your system from hanging if the network or remote identity server is slow or offline. Conversely, if you prioritize sssd first, remote identities will take precedence, which can be useful in environments where you want to override local accounts with network-provided ones.

The Importance of Order

You should always place your most reliable, highest-performance source first. Because NSS lookups are synchronous—meaning a process will wait until the lookup resolves or times out—placing a slow network-based source at the start of the chain can cause significant latency in system commands.

Key Takeaway: The nsswitch.conf file determines the sequence of identity resolution; always place local sources before remote ones to ensure system stability and performance during network outages.