In Linux, finding user account information and login details can be done through a variety of commands and files. Here are 12 methods, each with its own command code:
There are many ways to find user account information and login details in Linux, such as by looking at the /etc/passwd file:
cat /etc/passwd
You can use this command to list basic information about all users in the system.
View the /etc/shadow file
sudo cat /etc/shadow
This command requires the administrator permission and can be used to view user password information.
Use the getent command
getent passwd
The preceding command will obtain information about all users from the system.
Use id command
id username
Replacing username with the actual username, this command displays the user ID and group ID for the specified user.
Using the finger command
finger username
Replacing username with the actual username, this command displays the details of the specified user.
Use the who command
who
This command displays a list of users currently logged in to the system.
Use the w command
w
This command displays the details of the currently logged in user.
Use the last command
last
This command displays the user's login history.
Use the lastlog command
lastlog
The last login time of all users is displayed in the output.
View utmp and wtmp files
cat /var/run/utmp
cat /var/log/wtmp
These files record the current and historical login information, respectively.
Use the journalctl command
journalctl -u systemd-logind
This command displays the login and logout logs recorded by the systemd-logind service.
Use the awk and /etc/passwd files
awk -F: '{print $1 ":" $3 ":" $4 ":" $5 ":" $6 ":" $7}' /etc/passwd
This command displays the user's basic information in a formatted manner.
Some of the commands above require administrator privileges, so sudo may be added to the command. In addition, different linux distributions may have different configuration and log file locations. Adjust the file path and commands according to the actual situation.
EN
CN