getent

get entries from Name Service Switch libraries

getent [option]database key

Displays entries from databases supported by the Name Service Switch libraries, which are configured in /etc/nsswitch.conf.
If no key is provided, all entries will be displayed (unless the database does not support enumeration).
Entries for keys that match are displayed.

The database may be any of those supported by the GNU C Library

ahosts Without a key sethostent, gethostent and endhostent are called to enumerate the hosts database. This is the same as using hosts.
With keys each is passed to getaddrinfo with the address family AF_UNSPEC, enumerating each socket address structure returned.
ahostsv4 As with ahosts with address family AF_INET.
ahostsv6As with ahosts with address family AF_INET6. The call to getaddrinfo with AI_V4MAPPED flag.
aliases Without a key, use setaliasent, getaliasent and endaliasent to enumerate the aliases database.
With keyss , each is passed to getaliasbyname and display the result.
ethers Pass each key to ether_aton and ether_hostton until a result is obtained, and display the result.
group Without a key use setgrent, getgrent and endgrent to enumerate the group database.
With keyss, pass numeric keys to getgrgid and nonnumeric key to getgrnam and display the result.
gshadow Without a key use setsgent, getsgent, and endsgent to enumerate the gshadow database.
With keyss, pass each key to getsgnam and display the result.
hosts Without a key use sethostent, gethostent and endhostent to enumerate the hosts database.
With keys, pass each to inet_pton and then gethostbyaddr if IPv4 or gethostbyname2 and display the result.
initgroups Pass each key to getgrouplist and display the result. Enumeration is not supported on initgroups, so a key must be provided.
netgroup With one key pass it to and use getnetgrent display the resulting string triple (hostname, username, domainname).
With hostname, username, and domainname to match to a netgroup name via innetgr
Enumeration is not supported either one or three keys must be provided.
networks Without a key use setnetent, getnetent and endnetent to enumerate the networks database.
With keyss, pass each numeric key to getnetbyaddr and each nonnumeric key to getnetbyname and display the result.
passwd Without a key use setpwent, getpwent, and endpwent to enumerate the passwd database.
With keyss, pass numeric keys to getpwuid and nonnumeric key to getpwnam and display the result.
protocols Without a key use setprotoent, getprotoent and endprotoent to enumerate the protocols database.
With keyss, pass each numeric key to getprotobynumber and each nonnumeric key to getprotobyname and display the result.
rpc Without a key use setrpcent, getrpcent, and endrpcent to enumerate the rpc database.
With keyss, pass each numeric key to getrpcbynumber and each nonnumeric key to getrpcbyname and display the result.
services Without a key , use setservent, getservent, and endservent to enumerate the services database. With keyss, pass numeric key to getservbynumber and each nonnumeric key to getservbyname and display the result.
shadow Without a key use setspent, getspent, and endspent to enumerate the shadow database.
With keyss, pass each key in succession to getspnam and display the result.

Example

 at RWS > cat /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. 
# This file should be  sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned up nothing.
#  if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the # next entry.
#
# Valid entries include:
#
#       nisplus                 NIS+ (NIS version 3)
#       nis                     NIS (NIS version 2), also called YP
#       dns                     DNS (Domain Name Service)
#       files                   the local files
#       db                      the local database (.db) files
#       compat                  NIS on compat mode
#       hesiod                  Hesiod for user lookups
#       [NOTFOUND=return]       Stop searching if not found 
#

# To use db, put the "db" in front of "files" for entries to be
# looked up first in the databases
#
# Example:
#passwd:    db files nisplus nis
#shadow:    db files nisplus nis
#group:     db files nisplus nis

passwd:     files mysql sss
shadow:     files mysql sss
group:      files mysql sss

#hosts:     db files nisplus nis dns
hosts:      files dns

# Example - obey only what nisplus tells us...
#services:   nisplus [NOTFOUND=return] files
#networks:   nisplus [NOTFOUND=return] files
#protocols:  nisplus [NOTFOUND=return] files
#rpc:        nisplus [NOTFOUND=return] files
#ethers:     nisplus [NOTFOUND=return] files
#netmasks:   nisplus [NOTFOUND=return] files

bootparams: nisplus [NOTFOUND=return] files

ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   db files sss

netgroup:   db files sss

publickey:  nisplus

automount:  db files sss
aliases:    files nisplus

sudoers: files sss

Raspberry Pi example:
dapi2: > cat /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         files
group:          files
shadow:         files
gshadow:        files

hosts:          files mdns4_minimal [NOTFOUND=return] dns
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

OPTIONS

-s service
--service service
Override all databases with service.
-s database:service
--service database:service
Override databases
-i
--no-idn
Disables IDN encoding in lookups for ahosts/getaddrinfo
-?
--help
Output usage summary and exit.
--usage Output a short usage summary and exit.
-V
--version
Output the version number, license, and disclaimer of warranty for getent.

EXIT STATUS

0 success
1 Missing arguments, or database unknown.
2 key could not be found
3 Enumeration not supported on this database.

SEE ALSO

nsswitch.conf(5)