$linuxjunkies
>

getent(1)

Get entries from administrative databases (passwd, group, hosts, services, protocols, networks, etc.).

UbuntuDebianFedoraArch

Synopsis

getent [OPTION]... DATABASE [KEY]...

Description

getent retrieves entries from Name Service Switch (NSS) databases configured on the system. It queries the same sources that the C library uses (LDAP, NIS, files, etc.) and displays results in standard format. Common databases include passwd, group, hosts, services, protocols, networks, and aliases.

When a KEY is provided, getent returns only matching entries. Without a key, it displays the entire database. This is useful for verifying user/group lookups and debugging NSS configuration without parsing raw files directly.

Common options

FlagWhat it does
-s DATABASESpecify the service/source to query (e.g., files, ldap, nis) instead of following NSS order
-iUse case-insensitive key matching
--helpDisplay help message and list all available databases
--usageDisplay a short usage message
--versionShow version information

Examples

Look up the 'root' user in the passwd database; shows UID, GID, home directory, and shell

getent passwd root

Display all user entries from NSS passwd sources (similar to cat /etc/passwd but includes LDAP/NIS users)

getent passwd

Look up the 'sudo' group and display its GID and members

getent group sudo

Query the hosts database for 'localhost' entry

getent hosts localhost

Find the HTTP service and display its port number (typically 80/tcp)

getent services http

Look up user 'john' only in the local /etc/passwd file, bypassing LDAP/NIS

getent -s files passwd john

List all databases available on this system

getent --help | grep 'Supported databases'

Related commands