Linux for Developers Course
Linux for Developers
/
Beginner

whoami

Definition

A command that prints the effective username of the currently logged-in user.

Explain Like I'm New

Looking at your own nametag. It tells you exactly who the computer thinks you are right now.

Real World Example

You SSH into a massive corporate server. You aren't sure if you logged in as yourself or as the admin. You type `whoami` and it prints `root`. You immediately become very careful.

Common Use Cases

  • •Verifying active user
  • •Scripting conditions (e.g., abort if not root)

Interview Questions

basic

  • What will `whoami` output if you run it like this: `sudo whoami`?

intermediate

  • What is the difference between the `whoami` command and the `who` command?

Flash Cards

Question

Output of sudo whoami?

Click to reveal answer
Answer

It will output `root`, because `sudo` temporarily changes your effective user ID to the superuser.

Question

whoami vs who?

Click to reveal answer
Answer

`whoami` only prints your own username. `who` prints a list of EVERY user currently logged into the entire server, including where they logged in from.