fbpx List Linux Users: whoami, who, w and id | Certificação Linux

Find Linux Users: whoami, who, w, id & last

📅 12/09/2021 ⏱ 3 min ✍️ Uira Ribeiro
Linuxcommands
Find Linux Users: whoami, who, w, id & last
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

Learn how to identify users in Linux using the last, id, whoami, who, and w commands, to know who connected or is connected to the system.

Command last

The last utility shows the last connections made to the system and by which user:

$ lastec2-user pts/0        ip-10-8-0-6.ec2. Tue Apr 14 10:21   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)    

Command id

The id command shows the effective user and the real user in Linux.

Example:

$ iduid=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 logged into Linux is uiraribeiro, with User ID equal to 1000. The command also shows all groups the user belongs to.

With the "-un" option, the id command shows the User Name (login) of the user:

$ id -unuiraribeiro

With the "-u" option, id shows the User ID of the user.

uiraribeiro@ubuntu:~$ id -u1000

The id command can also show information for a specific user when the login is provided as a parameter:

$ id arthuruid=1001(arthur) gid=1001(arthur) groups=1001(arthur)

This command is usually useful for use in scripts, where you want to get the login or User ID of the user.

Command whoami

This command shows the login of the current user. It is the same as the "id -un" command.

$ whoamiuiraribeiro
$ id -unuiraribeiro

Command who

$ who

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

$ whoec2-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,05USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHATec2-user pts/0    ip-10-8-0-6.ec2. 10:21    5.00s  0.45s  0.00s w

The "w" command displays which command or program the users are currently running, as well as the average CPU usage at 1, 5, and 15 minutes.

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp