- Using the
lastcommand: Thelastcommand shows a list of all the users who have logged into the system, including the time and date of their last login. The command can be run as root or with sudo privileges.
- Show recent logins: The simplest use of the
lastcommand is to display a list of recent logins to the system. The command is run as follows:
Example: last
- Show the login history of a specific user: To show the login history of a specific user, add their username after the
lastcommand. For example:
Example: last username
- Show logins and logouts: By default, the
lastcommand only shows logins. To also show logouts, use the-foption. For example:
Example: last -f
- Show a specific number of logins: To show a specific number of logins, use the
-noption followed by the number of logins you want to see. For example:
Example: last -n 10
- Show the IP addresses used for remote logins: To see the IP addresses used for remote logins, use the
-ioption. For example:
Example: last -i
- Show the hostnames used for remote logins: To see the hostnames used for remote logins, use the
-Roption. For example:
Example last -R
- Show logins and system reboots: To show logins and system reboots, use the
-xoption. For example:
Example: last -x
- Show the reverse order of logins: To show the logins in reverse order, use the
-roption. For example:
Example: last -r
- Show logins and system shutdowns: To show logins and system shutdowns, use the
-aoption. For example:
Example: last -a
- Show logins for a specific period of time: To show logins for a specific period of time, use the
-toption followed by the desired time range. For example:
Example: last -t YYYYMMDDHHMMSS
Note: Replace YYYYMMDDHHMMSS with the desired start time in the format of year, month, day, hour, minute, and second.
- Using the
lastlogcommand: Thelastlogcommand shows the last time a user logged into the system. To view the login history of all users, run the command with the -a option. - Using the
wcommand: Thewcommand shows information about the currently logged in users, including their login time, the time they have been idle, and the command they are currently running. - Viewing the log files: The log files in the
/var/logdirectory also contain information about user logins and logouts. The log file/var/log/wtmpkeeps a record of all logins and logouts, and the/var/log/securefile contains information about authentication events, including successful and failed logins. - Using the
faillogcommand: Thefaillogcommand shows the number of failed login attempts for each user on the system. This can be useful in detecting unauthorized access attempts.