To list users in Linux, several methods can be employed depending on the desired level of detail and the type of users to be displayed.
1. Listing all local users from /etc/passwd:
The /etc/passwd file contains information about local user accounts. You can view its content using cat, more, or less.
Code

cat /etc/passwd

To extract only the usernames from this file, use awk or cut:
Code

awk -F: '{ print $1 }' /etc/passwd

Code

cut -d: -f1 /etc/passwd

2. Listing all users (including those from external authentication sources) with getent:
The getent command retrieves entries from databases configured in /etc/nsswitch.conf, including the passwd database. This command provides a comprehensive list of all users accessible to the system, including those from sources like NIS or LDAP.
Code

getent passwd

3. Listing currently logged-in users:
To see who is currently logged into the system, use the who, w, or users commands:
Code

who

Code

w

Code

users

4. Finding system users:
System users typically have UIDs below 1000 (though this can vary). You can filter the /etc/passwd file to find these accounts:
Code

awk -F: '($3 < 1000) { print $1 }' /etc/passwd