Listing logged-in users in Linux helps administrators understand who currently has access to a system and where connections originate. Monitoring active sessions improves accountability, reveals idle or stuck logins, and can highlight unexpected remote access attempts.
User logins are tracked through session records stored in binary databases such as utmp and wtmp, which are read by standard utilities. Commands like who and w provide a real-time view of active sessions, including terminal identifiers, login times, and remote host information. Tools such as last and lastlog query historical and per-user records to reconstruct previous login activity.
Access to these utilities normally requires only standard user privileges, but their output can reveal sensitive information such as usernames, hostnames, and IP addresses. Historical records may be rotated or truncated by log management policies, so very old sessions might no longer appear. On hardened systems, some fields may be anonymized or limited, and remote addresses might reflect bastion hosts or jump servers instead of original client IPs.
Related: How to check user login history in Linux
Related: How to force logout a user in Linux
$ whoami user
The output lists each active session with the username, terminal, login time, and remote host where applicable.
$ who user pts/0 2026-01-10 12:15 (203.0.113.10)
This view adds process information, idle time, and load averages to help identify busy or idle sessions.
$ w 12:15:48 up 6 min, 2 users, load average: 0.50, 0.18, 0.07 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT user 203.0.113.10 12:15 6:33 0.00s ? sshd: user [priv] user 203.0.113.10 12:14 6:33 0.00s 0.01s sshd: user [priv]
This history view helps identify previous access patterns and unexpected or failed sessions if logged.
$ last user pts/0 203.0.113.10 Sat Jan 10 12:15 still logged in user pts/0 203.0.113.10 Sat Jan 10 12:15 still running user pts/0 203.0.113.10 Sat Jan 10 12:15 still running user pts/0 203.0.113.10 Sat Jan 10 12:15 still running reboot system boot 6.8.0-90-generic Sat Jan 10 12:09 still running reboot system boot 6.8.0-84-generic Thu Jan 8 19:28 - 19:33 (00:04)
This command reduces the session list to a distinct set of usernames without duplicates.
$ who | awk '{print $1}' | sort | uniq
user
The lastlog output shows the last login timestamp, terminal, and remote host recorded for the selected user.
$ lastlog -u user Username Port From Latest user pts/0 203.0.113.10 Sat Jan 10 12:15:48 +0800 2026
This command shows the record associated with the active terminal and verifies that session tracking is working correctly.
$ who am i user pts/0 2026-01-10 12:15 (203.0.113.10)