getent(1)
Get entries from administrative databases (passwd, group, hosts, services, protocols, networks, etc.).
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
| Flag | What it does |
|---|---|
-s DATABASE | Specify the service/source to query (e.g., files, ldap, nis) instead of following NSS order |
-i | Use case-insensitive key matching |
--help | Display help message and list all available databases |
--usage | Display a short usage message |
--version | Show version information |
Examples
Look up the 'root' user in the passwd database; shows UID, GID, home directory, and shell
getent passwd rootDisplay all user entries from NSS passwd sources (similar to cat /etc/passwd but includes LDAP/NIS users)
getent passwdLook up the 'sudo' group and display its GID and members
getent group sudoQuery the hosts database for 'localhost' entry
getent hosts localhostFind the HTTP service and display its port number (typically 80/tcp)
getent services httpLook up user 'john' only in the local /etc/passwd file, bypassing LDAP/NIS
getent -s files passwd johnList all databases available on this system
getent --help | grep 'Supported databases'