How to Check the Current User in Linux (whoami)

whoami prints the username of the currently logged-in user running the shell.

Published October 2, 2026

whoami prints the username of the account you are currently using. id shows the user ID, group ID and group memberships too.

How it works

After su or sudo, whoami shows the effective user. who and w list everyone logged in.

Useful in scripts to ensure they are not run as root.

Try it

whoami
ada
id
uid=1000(ada) gid=1000(ada) groups=1000(ada),27(sudo)
sudo whoami
root

Practical examples

Current user

whoami

IDs and groups

id

Guard in a script

[ "$(id -u)" -eq 0 ] && { echo 'do not run as root'; exit 1; }

Who is logged in

who
w

Common mistakes

  • Assuming whoami shows the login user after su (it shows the effective user).
  • Running scripts as root unnecessarily.
  • Confusing UID 0 with the name root.

Key takeaways

  • whoami = effective username.
  • id = IDs and groups.
  • UID 0 is root.

FAQ

whoami vs logname?

logname shows the original login name.

How do I list groups?

groups.

More Linux articles