Skip to content

whoami Command in Linux (Find Logged In User)

On this page

whoami is an basic Unix/Linux command used to find username associated with current effective user id. This is generally used to identify the current logged in user in a shell. This command is also useful in shell scripts to identify the user id from which the script is running.

Syntax:

whoami [OPTION]...

whoami Command in Linux

Simply type the ‘whoami’ on command prompt to find logged in user in current shell.

whoami 

root

The above output shows that you are logged in with user ‘root’ in current shell. The same details can be find with id -un command in Linux.

id -un 

root

Let’s write a small bash shell script and check if script is running as root user or not. This is very useful to warn user that the script is running as root user.

Difference Between whoami and who am i Command

Both the commands whoami and who am i are used to get logged in username in Linux system. The username is defined in passwd file associate with effective user id.

When a user login as root on the network, then both whoami and who am i commands will return root.

whoami 

Output:>  root 

who am i 

Output:>  root     pts/14       2020-12-21 23:13 (150.242.65.112) 

But, when you logged in as another user (eg: rahul) and switched to root user (su – root). The whoami will show root but who am i will show the originally logged in user ‘rahul’.

whoami 

Output:>  root 

who am i 

Output:>  rahul     pts/14       2020-12-21 23:16 (150.242.65.112) 

Conclusion

In this tutorial, you have learn about Linux whoami command as well as difference with “who am i” command.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top