Using lslogins in Linux
The lslogins command in Linux is a powerful utility for displaying information about user accounts on the system. It provides detailed insights into both human and system accounts, making it a valuable tool for system administrators.Basic Usage
Running lslogins without any flags will display all accounts on your system, including system and application accounts:
Code:
lslogins
Popular Flags and Examples
Here are some popular flags you can use with lslogins:1. Display Last Login Information (-L)
The -L flag shows data about users' last login sessions.
Code:
lslogins -L
Sample Output:
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
1000 alice 0 no no 2025-Jan-04 Alice
1001 bob 0 no no 2025-Jan-03 Bob
2. Display User Accounts Only (-u)
The -u flag limits the output to only user accounts, excluding system accounts.
Code:
lslogins -u
Sample Output:
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
1000 alice 0 no no 2025-Jan-04 Alice
1001 bob 0 no no 2025-Jan-03 Bob
3. Display Process Information (-p)
The -p flag shows the number of processes each user is running.
Code:
lslogins -p
Sample Output:
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
0 root 5 no no 2025-Jan-04 root
1000 alice 2 no no 2025-Jan-04 Alice
1001 bob 1 no no 2025-Jan-03 Bob
4. Display Group Information (-G)
The -G flag, when combined with -u, shows users along with their group memberships.
Code:
lslogins -G -u
Sample Output:
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
1000 alice 0 no no 2025-Jan-04 Alice
Groups: alice, sudo
1001 bob 0 no no 2025-Jan-03 Bob
Groups: bob, users
lslogins -e will show detailed information about what each account is used for.
Additional Suggestions
- Combining Flags: You can combine multiple flags to get more specific information. For example, lslogins -L -u will show the last login information for user accounts only.
- Filtering by Group: Use the --groups option to display users belonging to a specific group.
- Failed Login Attempts: The -f flag displays information about users' last failed login attempts.
Code:
lslogins -f
Sample Output:
UID USER PROC PWD-LOCK PWD-DENY LAST-FAILED-LOGIN GECOS
1000 alice 0 no no 2025-Jan-02 Alice
1001 bob 0 no no 2025-Jan-01 Bob
The lslogins command is versatile and can be tailored to your specific needs by combining various flags and options. It's a handy tool for managing and monitoring user accounts on a Linux system.
I hope this article helps you understand and utilize the lslogins command effectively!