Knowing which users are currently logged into a system can be crucial for system administrators, especially when managing server resources, tracking user activity, or investigating potential security breaches. Fortunately, Linux provides tools for this exact purpose.
On a Linux system, multiple users can be logged in at the same time. This could be through physical console sessions, remote SSH connections, or other remote access mechanisms. Various commands, such as who, w, and last, allow administrators to see who's currently using the system, their activity, and their access methods.
Related: manage-user-sessions, audit-logs, restricting-access
$ who
The output will show the username, terminal, date, and IP from which they're accessing (if available).
$ w
This command displays details like idle time, the command they're executing, and more.
$ last
The result will show a list of previous logins, helping you track user activity over time.
$ who | awk '{print $1}' | sort | uniq
This chain of commands filters the output to display only unique usernames.
$ lastlog -u [username]
This will display the last login details for the specified user.
Comment anonymously. Login not required.