How to Determine the Current User Account in Linux

Share
  • April 9, 2019

Fatmawati Achmad Zaenuri/Shutterstock.com

If Linux means anything, it means choice. You can achieve even a simple task like identifying the current user in many ways. This tutorial will show you how to use some of the quickest and easiest methods.

Why would you need to find the identity of the current user? In many cases the owner of the computer is the only user and, without getting too existential, they probably know themselves. Perhaps, but it is also common for people to create additional user accounts to allow family members to have access to the computer. And, if you’re connected to a remote shell on a server somewhere, you may need a quick reminder of the username you’re logged in with. If you see a logged in session with no one in attendance, how do you identify the current user from the command line?

Let’s try the easiest option first. All we need to do is look at the command prompt. By default, Linux distributions have the username in the prompt. Simple. We didn’t even have to type a thing.

User name shown in command prompt

If the user has changed their prompt to some other format we need to try something else. The who command will give us the information we are looking for.

who

Output from the who command

The output from who gives you the name of the current user, the terminal they are logged in at, the date and time when they logged in. If it is a remote session, it also tell us where they are logged in from.

By comparison, the whoami command provides a very pithy answer:

whoami

Output from the whoami command

Read the remaining 21 paragraphs

Source : How to Determine the Current User Account in Linux