Query Users and Groups with getent
Resolve accounts and groups the way the system actually does — through NSS — instead of only grepping local files.
Run getent passwd username to fetch a user entry and getent group groupname to list a group's members, exactly as the system resolves them.
01Command
Command
$ getent passwd deploy
getent group docker02What it does
getent asks the NSS stack configured in /etc/nsswitch.conf, so it returns results from LDAP, SSSD, or Winbind too — a plain grep of /etc/passwd only sees local accounts. Output uses the same colon-separated format as the files, making it drop-in for scripts. Called with no key (getent passwd) it enumerates the whole database, which is how you build a complete user list on a domain-joined machine.
03Risk
!Warning: getent hosts is not getent ahosts: hosts uses the deprecated legacy lookup path, while ahosts goes through getaddrinfo and honors IPv6 properly.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- getent(1) — Linux manual pageEvidence: getent man page: 'getent - get entries from Name Service Switch libraries' listing supported databases passwd, group, hosts, services.
Last verified: 2026-09-17 · Category: Security & Privacy