Categories: Users and Groups

Identifying Users on Linux [Basic Guide]

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 
ec2-user pts/0 ip-10-8-0-6.ec2. Tue Apr 14 10:21am still logged in
ec2-user pts/0 ip-10-8-0-6.ec2. Mon Apr 13 23:26 - 00:10 (00:43)
ec2-user pts/5 ip-10-8-0-6.ec2. Sun Apr 12 15:52 - 01:50 (09:57)
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 
12:10:53 up 218 days, 22:52, 1 user, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
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.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Share
Published by
Uirá Endy Ribeiro

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.