getent

Name Service Switch database query tool

TLDR

Look up a passwd entry by UID
$ getent passwd [1000]
List every entry in the group database
$ getent group
Show members of one group name
$ getent group [group_name]
Resolve a hostname via hosts (NSS)
$ getent hosts [hostname]
List known services from the services database
$ getent services

SYNOPSIS

getent database [key...]

DESCRIPTION

getent queries entries from administrative databases configured in the Name Service Switch (NSS), including local files, LDAP, NIS, and other sources. It provides a unified interface to look up users, groups, hosts, and other system information regardless of where the data is stored.Unlike directly reading files like /etc/passwd, getent returns results from all configured NSS sources, making it essential for systems using centralized authentication (LDAP, Active Directory, etc.).Without a key, getent lists all entries in the database. With a key, it returns only matching entries.

PARAMETERS

passwd

User account database (/etc/passwd and NSS sources)
group
Group database (/etc/group and NSS sources)
hosts
Hostname/IP resolution (like /etc/hosts, DNS)
services
Network services (/etc/services)
protocols
Network protocols (/etc/protocols)
networks
Network names and addresses
shadow
Shadow password entries (requires root)
aliases
Mail aliases

CONFIGURATION

/etc/nsswitch.conf

Name Service Switch configuration determining which sources to query for each database type.

INSTALL

sudo apt install libc-bin
sudo apk add musl-utils
nix profile install nixpkgs#getent

CAVEATS

The shadow database requires root privileges. Some databases may not support enumeration (listing all entries). Results depend on NSS configuration in /etc/nsswitch.conf.

HISTORY

getent has been part of the GNU C Library (glibc) since the implementation of the Name Service Switch in the early 1990s, providing a standard way to query system databases that may come from multiple sources.

SEE ALSO

id(1), groups(1), host(1)