Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · users & permissions

whoami

which user am I

whoami prints one word: the account the shell is running as. It matters after su or sudo, when that may no longer be the account you logged in with — and before any command that would be dangerous as root.

One word, and worth checking: are you root right now, or yourself?

Prints
The effective user
who the system treats you as
After sudo
root
for that one command
More detail
id
ids and groups too
Who logged in
who am i
the original account

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

user@netflow — bashcoreutils
$ whoami
1user
2$ sudo whoami
root
3$ sudo -u www-data whoami
www-data
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
Your own account

The name the shell is running under — the same one in the prompt.

2
Under sudo, you are root

The command ran as root, so that is what it reports. It is a quick way to confirm that sudo works for you.

3
Or any other user

sudo -u runs a command as a named account. Running whoami this way tests whether you are allowed to.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

id

Shows the user id, group id and every group you belong to.

who

Lists everyone logged in to the machine.

echo $USER

The same name, from an environment variable.

logname

The name you originally logged in as, even after su.

In cybersecurity

It is the first command run on any newly gained shell.

What an intruder asks first

After exploiting a service, whoami shows which account was obtained. www-data means there is more work to do; root means there is not.

Know when you are root

A root prompt usually ends in # rather than $. If in doubt, ask — before running rm or chown, not after.

Services should not be root

A web application that reports root when it runs whoami is running with far more power than it needs.

Filed under

Users & permissions

Read alongside