Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
getent asks the name service switch (/etc/nsswitch.conf). So it finds users from /etc/passwd and from LDAP, IdM or Active Directory (through SSSD), and host names from /etc/hosts and DNS — exactly as the system sees them. cat /etc/passwd only shows local users.
Common databases: passwd, group, shadow, gshadow, hosts, ahosts, ahostsv4, ahostsv6, services, protocols, networks, netgroup, initgroups, aliases, ethers, rpc.
Zo schrijf je het
getent [OPTION]... DATABASE [KEY]...Belangrijkste delen
passwd- User accounts.
group- Groups and members.
shadow- Password data (root only).
hosts- Host names (files and DNS, by nsswitch order).
ahosts- Host names with getaddrinfo (all addresses, IPv4 and IPv6).
services- Port numbers of services (/etc/services).
initgroups- All groups of a user, also from LDAP/AD.
netgroup- NIS netgroups.
Opties 6
Meest gebruikt
Niets past bij dit filter.
Voorbeelden 12
$ als gewone gebruiker# als root (of met sudo)
1Show a user
getent passwd lisa lisa:x:1001:1001:Lisa Hassan:/home/lisa:/bin/bashWorks for local and directory (LDAP/AD) users.
2Show a group and its members
getent group wheel wheel:x:10:student,devops1The last field lists the members.
3Resolve a host name like programs do
getent hosts server2 192.168.122.20 server2Uses /etc/hosts first, then DNS (nsswitch order). nslookup/dig ask DNS only.
4All addresses of a name
getent ahosts www.redhat.comIPv4 and IPv6, like a browser sees them.
5Find the port of a service
getent services ssh https ssh 22/tcp https 443/tcpReads /etc/services.
6Check a directory user from AD/IdM
getent passwd anna@corp.example.comIf it shows nothing, check SSSD (
systemctl status sssd).7All groups of a user, also from AD
getent initgroups annaFast check when sudo rules use AD groups.
8Look only in local files
getent -s files passwd lisaTells you if a user is local or from the directory.
9List all normal users
getent passwd | awk -F: '$3 >= 1000 && $3 < 60000 {print $1}'nobody (65534) is not in this range.
10Read the password data (root)
getent shadow lisaLike the line in /etc/shadow.
11Test if a user exists in a script
Exit code 2 = not found.
12Show the order of the sources
grep -E '^(passwd|group|hosts):' /etc/nsswitch.conf passwd: files sss systemd group: files sss systemd hosts: files dns myhostnameRHEL manages this file with authselect.
Niets past bij dit filter.
Let op
getent passwdwithout a key may not list all directory users (SSSD does not enumerate by default).
Bestanden
/etc/nsswitch.conf- Which sources each database uses, in which order.
Exitcodes
0 :: Found. 1 :: Wrong arguments or unknown database. 2 :: One or more keys not found. 3 :: The database cannot list all entries.