Identifying Users on Linux
Learn how to identify users on Linux, using the last, id, whoami, who and w commands, to find out who connected or is connected to the system.
Last command
The last utility provides the last connections made to the system and by which user:
Id command
The id command shows which is the effective user and which is the real user on Linux.
Example:
Note that the user who is logged in to Linux is Uiraribeiro, with a User ID equal to 1000. The command also shows all the groups that the user is part of.
With the “-un” option, the id command shows the user’s User Name (login):
With the “-u” option, the id shows the user’s User ID.
The id command can also show information about a particular user when login is entered as a parameter:
This command is generally useful to be used in scripts where you want to get the user’s login or User ID.
Whoami command
This command shows the current user’s login. It’s the same as the “id -un” command.
Command who
$ who
The who utility can be used to show which users are logged in to the system:
Command w
The w utility also provides a list of which users are connected, but with other details:
The “w” command shows which command or program users are currently running, as well as the average CPU usage over 1, 5, and 15 minutes.