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

whoami

Print the user name you are working as right now (the effective user).

Niveau
Dagelijks Linux
Groep
Gebruikers en groepen
Root nodig
Nee
Pakket
coreutils

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

Wat het doet

whoami prints the name of the effective user: after su or sudo, that is the new user, not the one who logged in. It is the same as id -un.

To see the user who originally logged in, use logname or who am i.

Zo schrijf je het

whoami [OPTION]...

Opties 2

Meest gebruikt

--help
Show help.
--version
Show the version.

Voorbeelden 11

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

  1. 1Who am I?

    whoami
    student

    Your current user.

  2. 2After sudo

    sudo whoami
    root

    Proves that sudo works for you.

  3. 3After su

    su - admin -c whoami
    admin

    The command runs as admin.

  4. 4Compare with the login name

    sudo -i
    whoami; logname
    root
    student

    whoami = now, logname = who logged in.

  5. 5Stop a script that must run as root

    [ "$(whoami)" = "root" ] || { echo "Run this as root"; exit 1; }

    Many install scripts start with this check. [ "$EUID" -eq 0 ] works too.

  6. 6Stop a script that must NOT run as root

    [ "$(whoami)" != "root" ] || { echo "Do not run as root"; exit 1; }

    Build tools and package managers for users should not run as root.

  7. 7Show the user in a prompt or log

    echo "$(date) $(whoami)@$(hostname): backup started" >> /var/tmp/ops.log

    Who started the job, on which host.

  8. 8Check the user of a container

    podman run --rm registry.access.redhat.com/ubi10/ubi whoami
    root

    Many images run as root by default; a security scan would flag this.

  9. 9Check the user of a cron job

    crontab -l | grep whoami

    Put whoami > /tmp/cron-user.txt in a test job to see which user cron uses.

  10. 10Check the user after a privilege escalation test

    id; whoami

    In a pentest report, whoami output proves the reached privilege level.

  11. 11Use it in an SSH check

    ssh server2 whoami
    student

    Confirms the remote login user (useful with ProxyJump and keys).

Tips om te onthouden

  • whoami = effective user (after su/sudo). logname = original login. id = user plus groups.