Whoami Command: Find the Current User in Linux

whoami Linux command in Ubuntu
whoami Command (Ubuntu).

The whoami command lets you see which user account you're logged in to from a terminal window. This might seem pointless since you should know which account you're using, but it's not always clear when you're working in the command line.

For example, maybe you're working with an application that required you to log in as a different user, or maybe you've switched users so many times that you've lost track of whose credentials are currently active.

This guide shows you how to use the whoami command and the id command to find out who you are currently logged in as. 

Use whoami to Display Your Username

Having the terminal window show you which user you're actively logged in as is as simple as typing the following command:

whoami

The output of the above command simply shows the current user, like this:

jacob

To quickly see how this works with another user account — if you haven't made any other users in Linux — can use the sudo command to log in as root:

sudo su

Then, if you run the whoami command again, you'll be told that you're root.

How to Do It With id -un

In a strange circumstance where whoami isn't installed, there is another command you can use that can tell you your current username.

id -un

The result is exactly the same as the whoami command, so in our example, it would display jacob.

The id command can be used to show more than just the current user. It can also show the user id, group id, and groups that the user belongs to.

For example, you can show just the effective group the user belongs to by typing the following:

id -g

The above command only shows the group id. It doesn't show the group name. To show the effective group name, execute this command:

id -gn

You can display every group id that a user belongs to by entering this:

id -G

Again, the above command just shows the group ids. You can also use the Linux id command to display the group names:

id -Gn

If you just want to display your user id without the username, then simply run the following command:

id -u

More Information

You can use the --help switch with either whoami or id to find out the current man page for each program.

id --help
whoami --help

To see the current version of id or whoami, use the following commands:

id --version
whoami --version