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 ps Command: Inspect Running Processes

Linux ps Command: Inspect Running Processes

Learn how to inspect Running Processes with the Linux ps command, including practical examples, key options, and important precautions.

Linux sort Command: Sort Text Lines

Linux sort Command: Sort Text Lines

Learn how to sort text lines with the Linux sort command, including practical examples, key options, and important precautions.

Linux curl Command: Make URL Requests and Inspect HTTP Responses

Linux curl Command: Make URL Requests and Inspect HTTP Responses

Learn how to make URL Requests and Inspect HTTP Responses with the Linux curl command, including practical examples, key options, and important precautions.

Linux Disk Management: Partitioning, Formatting, and Mounting

Linux Disk Management: Partitioning, Formatting, and Mounting

Learn a safe Linux disk-management workflow for identifying devices, creating partitions and filesystems, mounting storage, and configuring persistent mounts.

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 more Command: View Text One Screen at a Time

Linux more Command: View Text One Screen at a Time

Learn how to use Linux more to read text one screen at a time, move and search interactively, start at a line or pattern, and choose between more and less.

Linux gunzip Command: Decompress gzip Files

Linux gunzip Command: Decompress gzip Files

Learn how to decompress gzip Files with the Linux gunzip command, including practical examples, key options, and important precautions.

Linux journalctl Command: Read systemd Logs

Linux journalctl Command: Read systemd Logs

Learn how to read systemd Logs with the Linux journalctl command, including practical examples, key options, and important precautions.

Linux traceroute Command: Trace Routers on the Way to a Host

Linux traceroute Command: Trace Routers on the Way to a Host

Learn how to trace Routers on the Way to a Host with the Linux traceroute command, including practical examples, key options, and important precautions.

Linux realpath Command: Resolve Absolute and Canonical Paths

Linux realpath Command: Resolve Absolute and Canonical Paths

Learn how to use the Linux realpath command to resolve relative paths, symbolic links, and redundant path components, with essential options, practical examples, output interpretation, and common troubleshooting tips.