How To Find Out The Current User Using Linux whoami Command

Linux whoami Command
Linux whoami Command.

Introduction

If you are a using your own computer it seems fairly obvious that the current user will be you. It is possible that you are logged in as a user other than you especially if you are using a terminal window.

For instance, if you used the following command you would actually be running as root.

sudo su

If you are logged into a Linux server at your place of work and you work in the support team then you may have to use different user accounts depending on the server or application you are working on.

Indeed sometimes you may have switched user so many times that you don't know which user's shell you are actually working in.

This guide shows you the command that you need to use to find out who you are currently logged in as. 

How To Display Your Current User Name

To show which user you are currently logged in as simply type the following command into your terminal window:

whoami

The output of the above command simply shows the current user.

You can try this out by opening a terminal window and entering the command. To prove it works run the command sudo su and then run the whoami command again.

If you really want to prove it works follow this guide for creating a new user and then switch to that user using the command su - . Finally run the whoami command again.

Find Out Your Username Using id -un

In a bizarre world where whoami isn't installed, there is another command you can use which will also tell you your current username.

Type the following command into a terminal window:

id -un

The result is exactly the same as the whoami command.

More About The id Command

The id command can be used to show more than just the current user.

Running the id command on its own shows the following information:

  • user id
  • group id
  • groups

You can narrow the information from the id command.

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

id -g

The above command only shows the group id. It doesn't show the group name. To show the effective group name run the following command:

id -gn

You can display all the group ids that a user belongs to with the following command:

id -G

Again the above command just shows the group ids. You can display the group names with the following command:

id -Gn

I have already shown you how to display your username using the id command:

id -un

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

id -u

Summary

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

id --help

whoami --help

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

id --version

whoami --version

Further Reading

If you liked this guide you might find these equally as useful: