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.

More in This Category
Linux zip Command: Create ZIP Archives

Linux zip Command: Create ZIP Archives

Learn how to create ZIP Archives with the Linux zip command, including practical examples, key options, and important precautions.

Linux man Command: Read Command Manual Pages

Linux man Command: Read Command Manual Pages

Learn how to use the Linux man command to find and read command manuals, sections, options, and related pages, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux sync Command: Flush Buffered Writes to Storage

Linux sync Command: Flush Buffered Writes to Storage

Learn how to flush Buffered Writes to Storage with the Linux sync command, including practical examples, key options, and important precautions.

Linux lscpu Command: Inspect CPU Architecture and Cores

Linux lscpu Command: Inspect CPU Architecture and Cores

Learn how to inspect CPU Architecture and Cores with the Linux lscpu command, including practical examples, key options, and important precautions.

Linux cp Command: Copy Files and Directories

Linux cp Command: Copy Files and Directories

Learn how to copy files and directories with Linux cp, control overwrites, preserve attributes, handle symlinks, and verify important copies.

Linux ssh-copy-id Command: Install a Public Key on a Remote Account

Linux ssh-copy-id Command: Install a Public Key on a Remote Account

Learn how to install a Public Key on a Remote Account with the Linux ssh-copy-id command, including practical examples, key options, and important precautions.

Linux history Command: Review and Reuse Shell Command History

Linux history Command: Review and Reuse Shell Command History

Learn how to use the Linux history command to review, search, reuse, and manage shell command history, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Tutorial / Understand systemd Services, Boot, and Logs

Linux Tutorial / Understand systemd Services, Boot, and Logs

Understand Linux boot stages and systemd units, distinguish active services from boot enablement, and inspect current-boot logs with systemctl and journalctl.

Linux find Command: Search Files by Name, Type, Size, and Time

Linux find Command: Search Files by Name, Type, Size, and Time

Learn how to search with Linux find by name, file type, size, and modification time, combine expressions, run commands safely, and verify targets before deletion.

Linux uniq Command: Remove or Count Adjacent Duplicate Lines

Linux uniq Command: Remove or Count Adjacent Duplicate Lines

Learn how to remove or count adjacent duplicate lines with the Linux uniq command, including practical examples, key options, and important precautions.