---
name: "getent"
section: "1"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd", "openbsd"]
url: "https://new.carta.tech/getent"
---

# getent(1)

get entries from Name Service Switch libraries

## NAME

getent - get entries from Name Service Switch libraries

## SYNOPSIS

**getent** \[*option* ...\] *database* *key* ...

## DESCRIPTION

The **getent** command displays entries from databases supported by the Name Service Switch libraries, which are configured in */etc/nsswitch.conf*. If one or more *key* arguments are provided, then only the entries that match the supplied keys will be displayed. Otherwise, if no *key* is provided, all entries will be displayed (unless the database does not support enumeration).

The *database* may be any of those supported by the GNU C Library, listed below:

- **ahosts**

  When no *key* is provided, use [**sethostent**(3)](/sethostent/3.md), [**gethostent**(3)](/gethostent/3.md), and [**endhostent**(3)](/endhostent/3.md) to enumerate the hosts database. This is identical to using [**hosts**(5)](/hosts/5.md). When one or more *key* arguments are provided, pass each *key* in succession to [**getaddrinfo**(3)](/getaddrinfo/3.md) with the address family **AF\_UNSPEC**, enumerating each socket address structure returned.

- **ahostsv4**

  Same as **ahosts**, but use the address family **AF\_INET**.

- **ahostsv6**

  Same as **ahosts**, but use the address family **AF\_INET6**. The call to [**getaddrinfo**(3)](/getaddrinfo/3.md) in this case includes the **AI\_V4MAPPED** flag.

- **aliases**

  When no *key* is provided, use [**setaliasent**(3)](/setaliasent/3.md), [**getaliasent**(3)](/getaliasent/3.md), and [**endaliasent**(3)](/endaliasent/3.md) to enumerate the aliases database. When one or more *key* arguments are provided, pass each *key* in succession to [**getaliasbyname**(3)](/getaliasbyname/3.md) and display the result.

- **ethers**

  When one or more *key* arguments are provided, pass each *key* in succession to [**ether\_aton**(3)](/ether_aton/3.md) and [**ether\_hostton**(3)](/ether_hostton/3.md) until a result is obtained, and display the result. Enumeration is not supported on **ethers**, so a *key* must be provided.

- **group**

  When no *key* is provided, use [**setgrent**(3)](/setgrent/3.md), [**getgrent**(3)](/getgrent/3.md), and [**endgrent**(3)](/endgrent/3.md) to enumerate the group database. When one or more *key* arguments are provided, pass each numeric *key* to [**getgrgid**(3)](/getgrgid/3.md) and each nonnumeric *key* to [**getgrnam**(3)](/getgrnam/3.md) and display the result.

- **gshadow**

  When no *key* is provided, use **setsgent**(3), **getsgent**(3), and **endsgent**(3) to enumerate the gshadow database. When one or more *key* arguments are provided, pass each *key* in succession to **getsgnam**(3) and display the result.

- **hosts**

  When no *key* is provided, use [**sethostent**(3)](/sethostent/3.md), [**gethostent**(3)](/gethostent/3.md), and [**endhostent**(3)](/endhostent/3.md) to enumerate the hosts database. When one or more *key* arguments are provided, pass each *key* to [**gethostbyaddr**(3)](/gethostbyaddr/3.md) or [**gethostbyname2**(3)](/gethostbyname2/3.md), depending on whether a call to [**inet\_pton**(3)](/inet_pton/3.md) indicates that the *key* is an IPv6 or IPv4 address or not, and display the result.

- **initgroups**

  When one or more *key* arguments are provided, pass each *key* in succession to [**getgrouplist**(3)](/getgrouplist/3.md) and display the result. Enumeration is not supported on **initgroups**, so a *key* must be provided.

- **netgroup**

  When one *key* is provided, pass the *key* to [**setnetgrent**(3)](/setnetgrent/3.md) and, using [**getnetgrent**(3)](/getnetgrent/3.md) display the resulting string triple (*hostname*, *username*, *domainname*). Alternatively, three *keys* may be provided, which are interpreted as the *hostname*, *username*, and *domainname* to match to a netgroup name via [**innetgr**(3)](/innetgr/3.md). Enumeration is not supported on **netgroup**, so either one or three *keys* must be provided.

- **networks**

  When no *key* is provided, use [**setnetent**(3)](/setnetent/3.md), [**getnetent**(3)](/getnetent/3.md), and [**endnetent**(3)](/endnetent/3.md) to enumerate the networks database. When one or more *key* arguments are provided, pass each numeric *key* to [**getnetbyaddr**(3)](/getnetbyaddr/3.md) and each nonnumeric *key* to [**getnetbyname**(3)](/getnetbyname/3.md) and display the result.

- **passwd**

  When no *key* is provided, use [**setpwent**(3)](/setpwent/3.md), [**getpwent**(3)](/getpwent/3.md), and [**endpwent**(3)](/endpwent/3.md) to enumerate the passwd database. When one or more *key* arguments are provided, pass each numeric *key* to [**getpwuid**(3)](/getpwuid/3.md) and each nonnumeric *key* to [**getpwnam**(3)](/getpwnam/3.md) and display the result.

- **protocols**

  When no *key* is provided, use [**setprotoent**(3)](/setprotoent/3.md), [**getprotoent**(3)](/getprotoent/3.md), and [**endprotoent**(3)](/endprotoent/3.md) to enumerate the protocols database. When one or more *key* arguments are provided, pass each numeric *key* to [**getprotobynumber**(3)](/getprotobynumber/3.md) and each nonnumeric *key* to [**getprotobyname**(3)](/getprotobyname/3.md) and display the result.

- **rpc**

  When no *key* is provided, use [**setrpcent**(3)](/setrpcent/3.md), [**getrpcent**(3)](/getrpcent/3.md), and [**endrpcent**(3)](/endrpcent/3.md) to enumerate the rpc database. When one or more *key* arguments are provided, pass each numeric *key* to [**getrpcbynumber**(3)](/getrpcbynumber/3.md) and each nonnumeric *key* to [**getrpcbyname**(3)](/getrpcbyname/3.md) and display the result.

- **services**

  When no *key* is provided, use [**setservent**(3)](/setservent/3.md), [**getservent**(3)](/getservent/3.md), and [**endservent**(3)](/endservent/3.md) to enumerate the services database. When one or more *key* arguments are provided, pass each numeric *key* to **getservbynumber**(3) and each nonnumeric *key* to [**getservbyname**(3)](/getservbyname/3.md) and display the result.

- **shadow**

  When no *key* is provided, use [**setspent**(3)](/setspent/3.md), [**getspent**(3)](/getspent/3.md), and [**endspent**(3)](/endspent/3.md) to enumerate the shadow database. When one or more *key* arguments are provided, pass each *key* in succession to [**getspnam**(3)](/getspnam/3.md) and display the result.

## OPTIONS

- **--service** *service* **-s** *service*

  Override all databases with the specified service. (Since glibc 2.2.5.)

- **--service** *database***:***service* **-s** *database***:***service*

  Override only specified databases with the specified service. The option may be used multiple times, but only the last service for each database will be used. (Since glibc 2.4.)

- **--no-idn** **-i**

  Disables IDN encoding in lookups for **ahosts**/[**getaddrinfo**(3)](/getaddrinfo/3.md) (Since glibc-2.13.)

- **--help** **-?**

  Print a usage summary and exit.

- **--usage**

  Print a short usage summary and exit.

- **--version** **-V**

  Print the version number, license, and disclaimer of warranty for **getent**.

## EXIT STATUS

One of the following exit values can be returned by **getent**:

- **0**

  Command completed successfully.

- **1**

  Missing arguments, or *database* unknown.

- **2**

  One or more supplied *key* could not be found in the *database*.

- **3**

  Enumeration not supported on this *database*.

## SEE ALSO

[**nsswitch.conf**(5)](/nsswitch.conf/5.md)
