getent
Linux · Users and permissions · reference only
What it does
Queries the system databases (users, groups, hosts, services) honouring the configured sources, not just local files.
Syntax
getent [opciones] base_de_datos [clave...]
Options and parameters
passwdUser database, equivalent to /etc/passwd.
groupGroup database, equivalent to /etc/group.
hostsResolves host names using /etc/hosts and DNS.
servicesLooks up the ports tied to services, as in /etc/services.
-s fuenteRestricts the lookup to one source from nsswitch.conf.
-iDisables conversion of internationalized domain names.
Usage examples
getent passwd anaShows the passwd line for the ana account.
getent group sudoShows the GID and members of the sudo group.
getent hosts example.comResolves example.com the way the system would.
getent passwd | cut -d: -f1Lists every account name, including LDAP or SSSD ones.
Notes and common mistakes
- It follows /etc/nsswitch.conf, which is why it finds users that are not in /etc/passwd.