- How to List Users in Linux
- Listing Users in Linux
- List Users with cat Command
- List Users with Terminal Pagers less and more
- List Users with awk Command
- List Users with getent Command
- Listing Normal and System users in Linux
- 12 Ways to Find User Account Info and Login Details in Linux
- 1. id Command – Show User and Group IDs
- 2. groups Command – View User Group Memberships
- 3. finger Command – Show User Information
- 4. getent Command – Fetch User Info from System Database
- 5. grep Command – Search for Patterns or Specific Text in Files
- 6. lslogins Command – Display User Information in Linux
- 7. users Command – List Current Logged-In Users on Linux
- 8. who Command – Show Information Of Currently Logged-In Users
- 9. w Command – Show Currently Logged-In User Activity
- 10. last Command – Show Most Recent Login Session
- 11. lastb Command – Show Failed Login Attempts
- 12. lastlog Command – List User Login Information
How to List Users in Linux
User management is a critical Linux system administration task. In large organizations, having insight into who has access to the system is crucial to correctly add users, remove users, and assign new user privileges.
This tutorial will show you how to list users on a Linux-based system. The guide provides four listing methods and explains essential concepts related to user administration.
Listing Users in Linux
Linux stores information about local users in the /etc/passwd file. Each line in the file contains information about a single user, including their username, user ID number (UID), home directory, and the login shell.
The following sections present multiple ways to access the data in /etc/passwd and list users on Linux distributions.
The commands used in the tutorial are:
Note: To display a list of the logged-on users and the information such as boot time, processes, hostnames, and more, use the who command.
List Users with cat Command
The cat command provides a straightforward way to list the contents of the /etc/passwd file.
The system outputs the entire file with all the users on the system.
To view the number of users only, pipe the output of the previous command to the wc command and make it count the number of lines:
The number of lines in /etc/passwd corresponds to the total number of users.
List Users with Terminal Pagers less and more
On systems with many users, it is useful to limit the /etc/passwd file output displayed at once. Use a terminal pager command, such as less or more , to browse through the file content line by line or page by page.
To open /etc/passwd using less , enter:
The first page of the file appears in the output. The list stops when it reaches the end of the terminal screen. Use the keyboard to navigate through the file.
Use more to get a similar result. This command is older and has a more limited set of functionalities:
List Users with awk Command
Use the awk command to list the usernames only, without additional information about each user. Since the data fields in /etc/passwd are separated by a colon symbol, the following syntax tells awk to output only the first field in each line:
Combine awk and less for a page-by-page view of the results.
List Users with getent Command
The getent command searches and displays system database entries. The searchable databases are listed in the /etc/nsswitch.conf file. By default, the file includes the passwd database.
List the entire contents of the passwd database by typing:
The output is the same as the output of the cat command.
However, you can use getent to look up specific users. To do so, use the following syntax:
If the user exists on the system, the command shows the related passwd entry line.
Listing Normal and System users in Linux
Linux-based systems have two types of users — system and normal users.
- System users are entities created by the system to run non-interactive processes, i.e., the processes that run in the background and do not require human interaction. The most important system user is root, which possesses administrative privileges.
- Normal users are human users created by root or another user with root privileges. Each normal user has a login shell and a home directory to store their files.
Both system and normal users in Linux have a unique user ID (UID) to identify them. System users have UIDs in the range from 0 (root user) to 999. Normal users typically receive UIDs from 1000 onwards, with each newly created user receiving the next smallest unused UID.
To check the UID range for normal users, use the grep command to search for the information stored in /etc/login.defs :
grep -E '^UID_MIN|^UID_MAX' /etc/login.defs
The output in this example shows that the smallest UID a normal user can receive is 1000, and the largest is 60000.
Use getent to search the passwd database by UID:
The output shows the user entry related to the UID.
Use UIDs in combination with getent to search for users in a range:
The command now lists all the users within the specified UID range.
This guide showed you how to list all Linux users, search for users, and find the number of Linux users in any Linux distribution.
12 Ways to Find User Account Info and Login Details in Linux
This article will show you useful ways to find information about users on a Linux system. Here we’ll describe commands to get a user’s account details, show login details as well what users are doing on the system.
If you want to add or create users in Linux, use the useradd command, and to modify or change any attributes of an already created user account, use the usermod command via the command line.
You might also like:
We’ll start by looking at 12 useful commands to find a user’s account information, then proceed to explain commands to view login details in the Linux system.
1. id Command – Show User and Group IDs
The id is a simple command line utility for displaying a real and effective user and group IDs identity information for the current user or specified user.
2. groups Command – View User Group Memberships
The groups command is used to display the group memberships for a user. It lists all the groups that a user belongs to, including both primary and supplementary groups.
3. finger Command – Show User Information
The finger command is used to search for information about a user on Linux, which includes detailed information about a specific user or a list of users, including their login name, real name, terminal, idle time, login time, and other relevant details.
The finger command doesn’t come pre-installed on many Linux distributions, you need to install it using your default package manager as shown.
$ sudo apt install finger [On Debian, Ubuntu and Mint] $ sudo yum install finger [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/finger [On Gentoo Linux] $ sudo apk add finger [On Alpine Linux] $ sudo pacman -S finger [On Arch Linux] $ sudo zypper install finger [On OpenSUSE]
It shows a user’s real name; home directory; shell; login: name, time; and so much more as shown below.
4. getent Command – Fetch User Info from System Database
The getent command is used to retrieve information from various databases, including the system user and group databases. It can be used to retrieve information about users, groups, hosts, networks, protocols, and other system entities that are stored in database files like /etc/passwd, /etc/group, /etc/hosts, etc.
To get a user’s account details, use the passwd database and the username as follows.
5. grep Command – Search for Patterns or Specific Text in Files
The grep command is a powerful command used to search for patterns or specific text in files. It allows you to filter and extract lines from text based on matching patterns. The name “grep” stands for “Global Regular Expression Print“.
You might also like:
You can use grep to find information about a specific user from the system accounts file: /etc/passwd as shown below.
6. lslogins Command – Display User Information in Linux
The lslogins command shows information about known users in the system, which typically includes details such as the username, UID (User ID), GID (Group ID), home directory, shell, last login time, and more, depending on the options used and the system configuration.
$ lslogins -u tecmint $ lslogins -u
7. users Command – List Current Logged-In Users on Linux
The users command is used to display the list of currently logged-in users on the Linux system.
8. who Command – Show Information Of Currently Logged-In Users
The who command is used to display users who are logged on to the system, including the username, terminal, login time, and remote host from which the user is logged in.
9. w Command – Show Currently Logged-In User Activity
The w command shows a summary of the currently logged-in users and their activity, which displays the login session, including the username, terminal, login time, idle time, JCPU (total CPU time used by all processes), PCPU (CPU time used by the current process), and the command or process running on the terminal.
10. last Command – Show Most Recent Login Session
The last command displays a list of the most recent login sessions, which includes information about the users who have logged in, their login times, and the terminals or remote hosts they used for login.
To show all the users who were present at a specified time, use the -p option as follows.
11. lastb Command – Show Failed Login Attempts
The lastb command is used to display a list of the last failed login attempts on the system. It reads from the system log file that records failed login attempts, typically stored in /var/log/btmp.
12. lastlog Command – List User Login Information
lastlog command is used to find the details of the most recent login information for all users or a specific user on the system, which provides details about the last login time and location for each user.
$ lastlog OR $ lastlog -u tecmint
That’s it! If you know any other command-line trick or command to view user account details do share with us.
You might also like:
In this article, we’ve explained various ways to find information about users and login details on a Linux system. You can ask any questions or share your thoughts via the feedback form below.