Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
Zo schrijf je het
whoami [OPTION]...Opties 2
Meest gebruikt
Niets past bij dit filter.
Voorbeelden 11
$ als gewone gebruiker# als root (of met sudo)
1Who am I?
whoami studentYour current user.
2After sudo
sudo whoami rootProves that sudo works for you.
3After su
su - admin -c whoami adminThe command runs as admin.
4Compare with the login name
whoami = now, logname = who logged in.
5Stop a script that must run as root
Many install scripts start with this check.
[ "$EUID" -eq 0 ]works too.6Stop a script that must NOT run as root
Build tools and package managers for users should not run as root.
7Show the user in a prompt or log
echo "$(date) $(whoami)@$(hostname): backup started" >> /var/tmp/ops.logWho started the job, on which host.
8Check the user of a container
podman run --rm registry.access.redhat.com/ubi10/ubi whoami rootMany images run as root by default; a security scan would flag this.
9Check the user of a cron job
Put
whoami > /tmp/cron-user.txtin a test job to see which user cron uses.10Check the user after a privilege escalation test
id; whoamiIn a pentest report,
whoamioutput proves the reached privilege level.11Use it in an SSH check
ssh server2 whoami studentConfirms the remote login user (useful with ProxyJump and keys).
Niets past bij dit filter.
Tips om te onthouden
- whoami = effective user (after su/sudo). logname = original login. id = user plus groups.