getent – get entries from administrative database
getent is Unix command which helps you query one of the following administrative databases in Unix: passwd, group, hosts, services, protocols, or networks.
Administrative databases in Unix
As you can probably see from their names, the administrative databases are here to help you gather the most vital information about your environment:
- passwd – can be used to confirm usernames, userids, home directories and full names of your users
- group – all the information about Unix groups known to your system
- services – all the Unix services configured on your system
- networks – networking information – what networks your system belongs to
- protocols – everything your system knows about network protocols
How To Use getent
My home Linux PC has a hostname of centos7. If I ever need to double-check which IPs this hostname points to, here’s how I can use getent:
getent passwd
Without additional parameters, this command will show you information about all the users available on your system. Most often this means “users locally created on your server”, but if NIS or LDAP are configured, this might show you a really long list of all the users in your organisation.
This is an example from my CentOS 7.4 setup:
Using getent to find a UID by username
getent accepts various keys when searching in databases. For the passwd one, you can user either username or user id (UID) to search the database.
Using getent to find a username by UID
Like I said, the opposite will work as well:
getent group
Without parameters, this will show you all the groups found on your Unix or Linux server:
Use getent to show Unix group
If you know a Unix group name, getent will help you confirm its numeric group ID and show members (usernames).
In this example below, system group mail has group ID of 12, and system user postfix as its member.
See also
- basic Unix commands
- Unix Commands
- id – print user identity
- who – see who is logged into the system
getent is Unix command which helps you query one of the following administrative databases in Unix: passwd, group, hosts, services, protocols, or networks.
Administrative databases in Unix
As you can probably see from their names, the administrative databases are here to help you gather the most vital information about your environment:
- passwd – can be used to confirm usernames, userids, home directories and full names of your users
- group – all the information about Unix groups known to your system
- services – all the Unix services configured on your system
- networks – networking information – what networks your system belongs to
- protocols – everything your system knows about network protocols
How To Use getent
My home Linux PC has a hostname of centos7. If I ever need to double-check which IPs this hostname points to, here’s how I can use getent:
getent passwd
Without additional parameters, this command will show you information about all the users available on your system. Most often this means “users locally created on your server”, but if NIS or LDAP are configured, this might show you a really long list of all the users in your organisation.
This is an example from my CentOS 7.4 setup:
Using getent to find a UID by username
getent accepts various keys when searching in databases. For the passwd one, you can user either username or user id (UID) to search the database.
Using getent to find a username by UID
Like I said, the opposite will work as well:
getent group
Without parameters, this will show you all the groups found on your Unix or Linux server:
Use getent to show Unix group
If you know a Unix group name, getent will help you confirm its numeric group ID and show members (usernames).
In this example below, system group mail has group ID of 12, and system user postfix as its member.
See also
- basic Unix commands
- Unix Commands
- id – print user identity
- who – see who is logged into the system