How To See The Users In Linux

5 min read

How to See the Users in Linux: A Complete Guide to Managing User Sessions and Accounts

Managing user sessions and accounts is a fundamental task for Linux administrators and power users alike. Whether you need to monitor active logins, audit system access, or troubleshoot connectivity issues, knowing how to see the users in Linux is essential. This practical guide covers all the primary commands and techniques to view both currently logged-in users and detailed account information, ensuring you maintain full visibility over your system's user activity It's one of those things that adds up..

Understanding Linux User Management

Before diving into commands, you'll want to understand that Linux tracks users in multiple ways. Which means the system maintains real-time information about active sessions, historical login records, and static account details stored in configuration files. Each method serves a different purpose, from immediate monitoring to long-term auditing Worth keeping that in mind. Less friction, more output..

Commands to See Currently Logged-In Users

1. The who Command

The who command displays all users currently logged into the system. It provides a straightforward view of active sessions That alone is useful..

who

Output example:

root     pts/0        2023-10-15 09:30 (192.168.1.100)
john     pts/1        2023-10-15 10:15 (192.168.1.105)

This shows the username, terminal, login time, and remote IP address. For a more compact view, use who -q to just count the users.

2. The w Command

The w command builds upon who by adding additional details about each user's activity, including their current process and CPU usage.

w

Output example:

USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.1.100    09:30     0.00   0.05   0.00 -bash
john     pts/1    192.168.1.105    10:15     5:23   0.02   0.00 vim report.txt

The w command is particularly useful for identifying what users are currently doing, making it easier to spot unusual activity or performance bottlenecks.

3. The users Command

For the simplest output, users just lists the usernames of all currently logged-in users without additional details.

users

Output example:

root john

We're talking about handy when you need a quick list for scripting or further processing No workaround needed..

Viewing Historical Login Records

4. The last Command

The last command shows a record of all past logins, including both successful and failed attempts. This is invaluable for security audits Easy to understand, harder to ignore. Nothing fancy..

last

Output example:

root     pts/0    192.168.1.100    Sun Oct 15 09:30 - 09:45  (00:15)
john     pts/1    192.168.1.105    Sun Oct 15 10:15 - 11:20  (01:05)
reboot   system   --               Sun Oct 15 08:00 - 09:30  (01:30)

You can filter results by user (last username), terminal (last -t pts/0), or time period (last -n 10 for the last 10 logins).

5. The lastlog Command

lastlog displays the most recent login time for each user account. Unlike last, which shows session logs, lastlog provides a per-user summary Still holds up..

lastlog

Output example:

Username         Port     Latest             From
root             pts/0    Sun Oct 15 09:30:00 2023 (192.168.1.100)
john             pts/1    Sun Oct 15 10:15:00 2023 (192.168.1.105)
daemon           Never logged in
bin              Never logged in

This is useful for identifying accounts that haven't been used recently, which might indicate stale or unused user accounts And that's really what it comes down to. Still holds up..

Examining User Account Information

6. The /etc/passwd File

The /etc/passwd file contains all user account information on the system. Each line represents a user with seven colon-separated fields:

cat /etc/passwd

Output example:

root:x:0:0:root:/root:/bin/bash
john:x:1000:1000:John Doe:/home/john:/bin/bash

The fields are:

  1. Username: The login name. Day to day, 2. Here's the thing — Password placeholder: Historically the password, now usually 'x' with actual passwords in /etc/shadow. 3. User ID (UID): A unique number identifying the user.
  2. Group ID (GID): The primary group number.
  3. That said, GECOS field: User's full name or description. 6. Home directory: The user's default directory.
  4. Shell: The default command-line interface.

For security, passwords are stored separately in /etc/shadow, which requires root privileges to access Not complicated — just consistent. And it works..

7. The getent Command

getent retrieves entries from system databases, including the passwd database. It's a more modern alternative to directly reading files.

getent passwd

This displays the same information as /etc/passwd but works consistently across different Linux distributions and authentication methods (like LDAP or NIS).

Advanced User Monitoring Techniques

8. Using ss or netstat for Network Connections

To see users via their network connections, combine ss with process information:

ss -tunp | grep ESTABLISHED

This shows established TCP/UDP connections along with the associated processes and user IDs.

9. Checking System Logs

For deeper historical analysis, examine system logs:

grep 'Accepted' /var/log/auth.log   # Debian/Ubuntu
grep 'sshd' /var/log/secure         # RHEL/CentOS

These logs record successful SSH logins, providing detailed audit trails Simple as that..

Security Considerations

When monitoring users, always respect privacy and organizational policies. Some commands like last and w might be restricted by PAM (Pluggable Authentication Modules) settings. If you encounter permission issues, you

If you encounter permission issues, you may need to use sudo or switch to the root account. That said, follow the principle of least privilege: avoid running monitoring tools as root unless absolutely necessary, and instead configure specific sudoers rules that grant access only to the commands required for auditing. Also, remember that login records and authentication logs contain sensitive information; restrict access to these files and ensure they are rotated and backed up according to your organization’s data retention policy.

Quick Reference Summary

Command Primary Use
who Lists users currently logged in
w Shows logged-in users and their active processes
last Displays historical login sessions and reboots
lastlog Reports the most recent login for every user account
getent passwd Retrieves user account details from system databases
ss -tunp Identifies active network connections and associated users

You'll probably want to bookmark this section.

Conclusion

Monitoring user activity is a fundamental responsibility of Linux system administration. By combining real-time tools like who and w with historical records from last, lastlog, and system logs, administrators can detect unused accounts, spot unauthorized access, and maintain a clear audit trail. Pair these technical measures with clear policies, least-privilege access, and regular account reviews to keep your systems secure and compliant Most people skip this — try not to. And it works..

Hot Off the Press

Newly Live

Dig Deeper Here

Still Curious?

Thank you for reading about How To See The Users In Linux. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home