Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Find User Account Info and Login Details in Linux?
For system administrators, monitoring user account information is essential for security and system management. Linux provides several powerful commands to gather details about users, their login history, group memberships, and current activity.
id Command
The id command displays user and group identification numbers along with group memberships. It shows details for the current user by default, or you can specify a particular user.
id id 2112
Running the above commands gives us the following result ?
uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare) uid=2112(uname1) gid=2112(uname1) groups=2112(uname1)
The output shows the user ID (uid), primary group ID (gid), and all secondary groups the user belongs to.
groups Command
The groups command displays group names that the currently logged-in user belongs to. It provides a simplified view compared to the id command.
groups groups ubuntu
Running the above code gives us the following result ?
ubuntu adm cdrom sudo dip plugdev lpadmin sambashare ubuntu : ubuntu adm cdrom sudo dip plugdev lpadmin sambashare
getent Command
The getent command retrieves entries from administrative databases like passwd, group, and hosts. It's particularly useful for viewing user account information from /etc/passwd.
getent passwd getent passwd ubuntu
Running the above code gives us the following result ?
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin ubuntu:x:1000:1000:ubuntu,,,:/home/ubuntu:/bin/bash ubuntu:x:1000:1000:ubuntu,,,:/home/ubuntu:/bin/bash
Each line shows username, password placeholder, UID, GID, user info, home directory, and default shell.
lslogins Command
The lslogins command provides a comprehensive overview of system users, including login history and account status. The -u flag shows only regular users.
lslogins -u
Running the above code gives us the following result ?
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS 0 root 135 root 1000 ubuntu 70 23:04:25 ubuntu,,, 2112 uname1 0 storefront 9002 uname4 0 HR
This shows UID, username, number of processes, password status, and last login time.
w Command
The w command displays currently logged-in users and their active processes. It shows system uptime, load average, and detailed user session information.
w
Running the above code gives us the following result ?
08:13:17 up 12:26, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT ubuntu tty7 :0 23:04 12:58m 1:23 0.34s /sbin/upstart --user
Quick Reference
| Command | Purpose | Key Information |
|---|---|---|
id |
User/group IDs | UID, GID, group memberships |
groups |
Group membership | Group names only |
getent passwd |
User account details | Complete passwd entries |
lslogins |
User overview | Login history, account status |
w |
Active users | Current sessions, processes |
Conclusion
These Linux commands provide comprehensive user account information for system administration tasks. Use id and groups for quick user details, getent for complete account information, lslogins for user overviews, and w for monitoring active sessions.
