DEV Community

Alex
Alex

Posted on

6 1

Difference between the whoami and who am i commands

In the world of Linux, where command-line proficiency is a valuable skill, understanding the nuances of various commands can significantly enhance user experience and system administration. Two such commands that often cause confusion due to their similar syntax and functionality are whoami and who am i. Despite their apparent similarities, these commands serve different purposes and provide distinct outputs.

The whoami Command:
The whoami command is straightforward; it displays the username of the current userβ€”the effective user ID (EUID) running the shell or script. It's a simple command without options, and its output is the username that you're operating under after any initial logins or user switches.

Example:

$ whoami
john_doe
Enter fullscreen mode Exit fullscreen mode

The who am i Command:
On the other hand, who am i is a usage of the who command with the am i option. This command provides information about the original user who logged into the system, even if you've switched users using the su command. It's particularly useful for checking the real user ID (RUID) when you're operating under a different user's environment.

Example:

$ su - jane_doe
$ who am i
john_doe   pts/0        2024-04-08 23:20 (:0)
Enter fullscreen mode Exit fullscreen mode

In this example, even though the current effective user is jane_doe, who am i returns john_doe, which is the user that originally logged into the system.

Comparative Analysis:
The key difference lies in the context of the user identity they report. whoami gives you the identity under which the current process is running, which could be the result of a series of user switches. In contrast, who am i provides the identity of the user who initiated the session, regardless of any subsequent su commands.

Practical Use Cases:

  • whoami is commonly used in scripts to check the current user before executing commands that require specific user privileges.
  • who am i is helpful for system administrators to track the original login, especially when multiple su commands are used to switch between users.

Image of Docusign

πŸ› οΈ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (1)

Collapse
 
dreamhollow4219 profile image
Ian β€’

Interesting.

There's a lot I still don't know about the "server side" implementation of Linux that this clearly caters towards. Still a lot I don't fully understand about this OS.

But seeing this reminds me of a video I saw several months ago talking about Linux and multi-seating in regards to older computer usage.

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

πŸ‘‹ Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay