Skip to content

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:

$ last <br></br>ec2-user pts/0 ip-10-8-0-6.ec2. Tue Apr 14 10:21am still logged in <br></br>ec2-user pts/0 ip-10-8-0-6.ec2. Mon Apr 13 23:26 - 00:10 (00:43) <br></br>ec2-user pts/5 ip-10-8-0-6.ec2. Sun Apr 12 15:52 - 01:50 (09:57) <br></br>ec2-user pts/0 ip-10-8-0-6.ec2. Sun Apr 12 15:51 - 01:50 (09:59)

Id command

The id command shows which is the effective user and which is the real user on Linux.

Example:

$ id uid=1000 (uiraribeiro) gid=1000 (uiraribeiro) groups=1000 (uiraribeiro), 4 (adm) ,24 (cdrom) ,27 (sudo) ,30 (dip) ,46 (plugdev) ,119 (lpadmin) ,130 (lxd) ,131 (sambashare)

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):

$ id -un uraribeiro

With the “-u” option, the id shows the user’s User ID.

Uiraribeiro @ubuntu: ~$ id -u 1000

The id command can also show information about a particular user when login is entered as a parameter:

$ id Arthur uid=1001 (Arthur) gid=1001 (Arthur) Groups=1001 (Arthur)

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.

$ whoami uiraribeiro
$ id -un uraribeiro

Command who

$ who

The who utility can be used to show which users are logged in to the system:

$ who ec2-user pts/0 2015-04-14 10:21 (ip-10-8-0-6.ec2.internal)

Command w

The w utility also provides a list of which users are connected, but with other details:

$ w <br></br>12:10:53 up 218 days, 22:52, 1 user, load average: 0.00, 0.01, 0.05 <br></br>USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT <br></br>ec2-user pts/0 & nbsp; ip-10-8-0-6.ec2. 10:21 5.00s 0.45s 0.00s w

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.