LinuxCommandLibrary

whoami

Display current user's username

TLDR

Display currently logged username

$ whoami
copy

Display the username after a change in the user ID
$ sudo whoami
copy

SYNOPSIS

whoami

DESCRIPTION

The whoami command displays the effective user ID (UID) associated with the current login session. It essentially tells you which user the current process is running as. This is useful for verifying your identity after using commands like su or sudo, or within scripts to ensure actions are performed under the intended user context. It is a simple but crucial tool for security auditing and user management in Linux environments.
The output is typically the username associated with that UID, not the numerical UID itself. It provides a human-readable identifier of the active user within the terminal session.

CAVEATS

The whoami command only reflects the effective user ID. It might not accurately represent the real user ID in all circumstances, particularly when special capabilities or setuid bits are in play. It's a quick check, but not a definitive security audit tool.

EXAMPLES

Typing whoami in the terminal will simply print the username of the current user logged in.

HISTORY

The whoami command has been a staple in Unix and Linux systems for many years. Its simplicity and utility in identifying the current user have made it a fundamental part of shell scripting and system administration workflows since the early days of these operating systems.

SEE ALSO

id(1), logname(1), who(1)

Copied to clipboard