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

id

Show the UID, primary group and all groups of a user (or of yourself).

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

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

Without a name id shows the data of the current process: the user and the groups that are active now. With a name it reads the account data, so it already shows new groups that the logged-in user does not have yet.

With SELinux on, id without a name also shows the security context.

Zo schrijf je het

id [OPTION]... [USER]...

Opties 10

Meest gebruikt

-u, --user
Only the UID.
-g, --group
Only the primary GID.
-G, --groups
All GIDs.
-n, --name
Names instead of numbers (with -u, -g, -G).
-r, --real
The real ID instead of the effective ID (with -u, -g, -G).
-Z, --context
Only the SELinux context.
-z, --zero
Separate items with NUL (not with the default output).
-a
Ignored (for other systems).
--help
Show help.
--version
Show the version.

Voorbeelden 11

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

  1. 1Your own IDs

    id
    uid=1000(student) gid=1000(student) groups=1000(student),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

    You are in wheel, so you may use sudo.

  2. 2Another user

    id lisa
    uid=1001(lisa) gid=1001(lisa) groups=1001(lisa),1100(webadmins)

    Check new group memberships here.

  3. 3Only the UID

    id -u
    1000

    In scripts: [ "$(id -u)" -eq 0 ] tests for root.

  4. 4Only the user name

    id -un
    student

    Same as whoami.

  5. 5All group names

    id -Gn lisa
    lisa webadmins

    Easy to grep.

  6. 6Check if a user is in a group

    id -nG lisa | grep -qw wheel && echo "lisa is admin"

    -w matches the whole word only.

  7. 7See the SELinux context

    id -Z
    unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

    Shows the SELinux user, role and type of your shell.

  8. 8Real and effective user

    sudo id -u; sudo id -ru
    0
    0

    sudo sets both to root. Programs with setuid only change the effective ID.

  9. 9Compare the active groups with the account

    id -Gn; id -Gn $USER

    When the second list is longer, log in again (or use newgrp).

  10. 10Check the user of a container

    podman run --rm registry.access.redhat.com/ubi10/ubi id
    uid=0(root) gid=0(root) groups=0(root)

    Root in a container: check it in a security review.

  11. 11Check a service account

    id apache
    uid=48(apache) gid=48(apache) groups=48(apache)

    A system account (UID under 1000).

Tips om te onthouden

  • id USER = account data. id = what your shell has now.

Exitcodes

0Done.
1The user does not exist or another error.