cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Starfighter Starfighter
Starfighter
  • 373 Views

Current User Logged In

Which of the following commands displays the
username of the currently logged in user?

- who

- whoami

- id

- username

 

 

Trevor "Red Hat Evangelist" Chandler
Labels (3)
8 Replies
Ad_astra
Flight Engineer Flight Engineer
Flight Engineer
  • 338 Views

Hi

The answer to this question is the 'whoami' command.

The 'who' command returns all the users currently logged in to the system.

The 'id' command returns the current user's id (uid), their group id (gid) and all groups they are members of.

I am not aware of the username command!

Regards

AA

Trevor
Starfighter Starfighter
Starfighter
  • 318 Views

I'm liking the "id" command, as well as the "whoami" command.

Granted, the "id" command displays userid, groupid, etc. information.
Had the query been phrased as "...displays ONLY the username ...",
then the "whoami" command certainly would have the only
acceptable choice. However, I do understand your reasoning.

Thanks for responding!!!

Trevor "Red Hat Evangelist" Chandler
Tracy_Baker
Starfighter Starfighter
Starfighter
  • 286 Views

You forgot this one: w

(Yes, just w. Look for the tty* entry.)

 

Program Lead at Arizona's first Red Hat Academy, est. 2005
Estrella Mountain Community College
Trevor
Starfighter Starfighter
Starfighter
  • 283 Views

Tracy, I didn't forget the 'w' command.
I deliberately left it out, to entice you to
weigh in - and it worked

And you are saying that the 'w' command,
by itself, will NOT display the username
of the currently logged in user, right?

I would provide a screenshot of what the
'w' command actually displays, but I don't
want to deprive other readers from looking
at this on their own system.

 

 

Trevor "Red Hat Evangelist" Chandler
abhidd
Mission Specialist
Mission Specialist
  • 267 Views

If you run the w command without any options, it displays the following information:

Output columns:

  1. USER: The username of the logged-in user.
  2. TTY: The terminal from which the user is logged in.
  3. FROM: The IP address or hostname from which the user is logged in.
  4. LOGIN@: The time when the user logged in.
  5. IDLE: The amount of time the user has been idle.
  6. JCPU: The time used by all processes attached to the terminal.
  7. PCPU: The time used by the current process.
  8. WHAT: The command the user is currently running.
Trevor
Starfighter Starfighter
Starfighter
  • 232 Views

abhidd, I agree with you 101% that the 'w' command, without any options, displays all of the columns.  However, there's not a single piece of information, for any user, in either of those columns - especially for what the initial query is asking for: currently logged in user.

Thanks for your response!!!

Trevor "Red Hat Evangelist" Chandler
Chetan_Tiwary_
Community Manager
Community Manager
  • 223 Views

Chetan_Tiwary__1-1741720602812.png

 

The who command displays details regarding users currently logged into the system, detailing usernames, terminal sessions, login timestamps, and, when applicable, remote host data. This information is derived from parsing system files such as /var/run/utmp and /var/log/wtmp, which track login and logout activities. In contrast, whoami provides a straightforward display of the current user's effective username, achieved through a direct query of the process's Effective User ID (EUID).

Gopinath_Pigili
Flight Engineer
Flight Engineer
  • 97 Views

I will go with "whoami" command, This command specifically displays the username of the currently logged-in user. ofcourse you can also use id -un

Regards

Gopinath

0 Kudos
Join the discussion
You must log in to join this conversation.