whoami
Display current user's username
TLDR
Display currently logged username
Display the username after a change in the user ID
SYNOPSIS
whoami [OPTION]...
PARAMETERS
--help
--help
Display a help message and exit.
--version
--version
Output version information and exit.
DESCRIPTION
whoami is a fundamental Linux command used to print the effective user ID name of the current user. It's a simple yet powerful tool for quickly determining which user account is currently executing commands. Unlike logname, which displays the user who logged in initially, whoami shows the user under whose privileges the current shell is operating. This distinction is crucial when using commands like su or sudo to temporarily switch user identities. For example, if you log in as userA and then use su userB, whoami will report userB, while logname would still report userA. It essentially tells you "who you are right now" in terms of your effective user ID. It is commonly used in scripts to check permissions or to log operations under the current user's context.
CAVEATS
While whoami is straightforward, it's important to understand it reports the effective user ID, not necessarily the original login user ID. This can be different if su or sudo commands have been used to change the user context. For the original login name, logname might be more appropriate. For more detailed user and group information, id should be used.
EFFECTIVE VS. REAL USER ID
whoami prints the effective user ID name, which is the identity under which the current process is running. This can differ from the real user ID (the user who originally logged in) if commands like su or sudo are used to change user privileges without initiating a full login shell.
SECURITY CONTEXT
Understanding the output of whoami is critical in security contexts, as it directly indicates the permissions and privileges associated with the currently executing commands.
HISTORY
The whoami command has been a standard part of Unix-like operating systems for a long time. In GNU/Linux systems, it is part of the GNU Coreutils package, which provides essential system utilities. Its simplicity and clear purpose have made it a ubiquitous command for quickly identifying the current user context, especially useful in shell scripting and interactive sessions. Its design primarily focuses on providing the effective user ID, reflecting the common need to know "who is executing this right now."