Where to start First steps track · 15 stages
Linux Labs

whoami — identify the effective user

3 min Ubuntu 24.04; GNU coreutils 9.4

whoami prints the user name tied to the process's effective user ID — the account you act as now.

Cheat sheet

4 commands Printable version
  • whoami effective user
  • id -u numeric UID
  • id -un same user name
  • whoami --help help

Overview

whoami resolves the process’s effective user ID to an account name. It identifies the account used for this command, not the owner of the terminal window.

A normal student session reports student. An authorised sudo invocation may report a different account. The command neither lists groups nor establishes who originally logged in. It does not obtain its answer from USER, an environment variable that can differ from the process credentials.

Options

2

There are no operational options: the plain invocation does the job. The golden version provides only --help and --version. Do not pass another user name as an operand; use id student for that account. Success returns zero; inability to resolve the name is an error.

Option What it does Example
--help Display help and exit. whoami --help
--version Report the coreutils version when comparing implementations. whoami --version

Nothing found. Try a shorter query.

Recipes

3

Check the current identity

Compare the name with the numeric identity. Names are readable; a UID helps diagnose permissions.

bash
whoami
id -u

Inspect a sudo invocation

The training VM permits sudo. This identifies the account for one command; it does not turn the current shell into a root shell.

bash
sudo whoami

Inspect another account

Use id to inspect student; whoami does not accept a user operand.

bash
id student

Troubleshooting

3

Passing a user name fails

whoami has no target-user argument. Remove it for the current identity or use id for another account.

bash
whoami

Expected student but got root

Check whether you are in a privileged shell. Changing USER or file permissions does not correct the execution context.

bash
id

The UID exists but its name cannot be resolved

The numeric identity may lack an accessible account entry. Inspect the UID and its account mapping before creating or changing accounts.

bash
id -u
getent passwd "$(id -u)"

Danger zone

The command only reads information. A root result is not permission to make administrative changes. In automation, check the exit status and do not use USER as proof of privileges.

See also

Loading…