Linux whoami Command: Show the Effective User Name
whoami prints the effective username of the process running the current command in a single line. It allows you to quickly check which user a shell or script is actually running as when run with changed privileges.
What is the whoami command?
It is not always the same as the original account name used at login. In environments where the effective user ID has been changed with sudo or su, it shows the name associated with that effective ID. If you also need the numeric ID and group, use id.
Basic syntax
whoami [option]
The installed implementation and options may vary depending on the distribution. Check the current system documentation with man whoami.
Examples
Checking the current effective user
Usually, it shows the login account, but after switching privileges, it may show the switched account.
whoami
Comparing sudo environments
This command may be run with administrative privileges and output root. It is not meant to check whether the user can use sudo.
sudo whoami
Also check the user ID
id displays more detailed information about the user and group IDs.
id
Meaning of the displayed username
What whoami displays is the effective username of the current process. The following results are examples, and the actual name depends on the login account and whether privilege escalation has occurred.
whoami
Example output:
alice
The reason sudo whoami may show root is that the effective user of the command executed by sudo changes. This is different from a command that tells you who the original logged-in user is. To check numeric UID and groups, use id.
Main Options and Format
| Options/Format | Description |
|---|---|
--help |
View a brief usage of the installed GNU implementation. |
--version |
View the version of the installed GNU implementation. |
Precautions when using
The result of whoami alone does not reveal the original account that logged in, all group memberships, or the range of sudo privileges. Compare the account that started the login with logname and the numeric ID of the current process with id. Depending on the environment, the original login session information may not exist.
Frequently Asked Questions
Are whoami and id -un the same?
In a typical GNU environment, both show the name of the currently effective user ID. id has additional options to check groups and numeric IDs.
Official Documentation
The exact behavior of the options and implementation-specific differences can be found in the official documentation related to whoami.









