Today I learned about the nsswitch config file. The /etc/nsswitch.conf file is used to configure which services are to be used to determine information such as hostnames, password files, and group files.
An example of the /etc/nsswitch.conf
# Name Service Switch configuration file.
# See nsswitch.conf(5) for details.
passwd: files systemd
group: files [SUCCESS=merge] systemd
shadow: files systemd
gshadow: files systemd
publickey: files
hosts: mymachines resolve [!UNAVAIL=return] files myhostname dns
networks: files
protocols: files
services: files
ethers: files
rpc: files
netgroup: files
The syntax is the following:
database_name: (service_specifications...[STATUS=ACTION])
database_name: is the database name we will be looking for.service_specification: where we’ll be looking. Depend on the presence of shared libraries. (e.gfiles,db,ldap,winbind…)STATUS: a resulting status for service_specification if it occursACTIONis taken.
In the previous example:
- for
passwd,group,shadowandgshadowthe system will look in the files first then it will fallback to systemd. - for
groupif the lookup in the files succeeds, the processing will continue to systemd and will merge the member list of the already found groups will be merged together. - for
hostsit will usemymachinesplugin, thenresolve. Ifresolveis available it will return (stop the lookup) otherwise it will continue tofiles,myhostnameand finallydns. - for other services it will use
files.