Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

getent

Look up entries in the system databases (users, groups, hosts, services …) the same way programs do.

Niveau
RHCSA-examen
Groep
Gebruikers en groepen
Root nodig
Nee
Pakket
glibc-common

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

-s, --service SERVICE
Use this source only (like files or sss).
-s, --service DATABASE:SERVICE
Use this source only for one database.
-i, --no-idn
Do not use IDN encoding for host lookups.
-?, --help
Show help.
--usage
Short usage.
-V, --version
Show the version.

Voorbeelden 12

$ als gewone gebruiker# als root (of met sudo)

  1. 1Show a user

    getent passwd lisa
    lisa:x:1001:1001:Lisa Hassan:/home/lisa:/bin/bash

    Works for local and directory (LDAP/AD) users.

  2. 2Show a group and its members

    getent group wheel
    wheel:x:10:student,devops1

    The last field lists the members.

  3. 3Resolve a host name like programs do

    getent hosts server2
    192.168.122.20  server2

    Uses /etc/hosts first, then DNS (nsswitch order). nslookup/dig ask DNS only.

  4. 4All addresses of a name

    getent ahosts www.redhat.com

    IPv4 and IPv6, like a browser sees them.

  5. 5Find the port of a service

    getent services ssh https
    ssh                   22/tcp
    https                 443/tcp

    Reads /etc/services.

  6. 6Check a directory user from AD/IdM

    getent passwd anna@corp.example.com

    If it shows nothing, check SSSD (systemctl status sssd).

  7. 7All groups of a user, also from AD

    getent initgroups anna

    Fast check when sudo rules use AD groups.

  8. 8Look only in local files

    getent -s files passwd lisa

    Tells you if a user is local or from the directory.

  9. 9List all normal users

    getent passwd | awk -F: '$3 >= 1000 && $3 < 60000 {print $1}'

    nobody (65534) is not in this range.

  10. 10Read the password data (root)

    getent shadow lisa

    Like the line in /etc/shadow.

  11. 11Test if a user exists in a script

    getent passwd lisa >/dev/null && echo exists || echo missing

    Exit code 2 = not found.

  12. 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 myhostname

    RHEL manages this file with authselect.

Let op

  • getent passwd without 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.