Show Login History
The last command displays a list of user logins and system boots by reading the wtmp log file. It shows information about when users logged in and out of the system, including login duration and terminal information. This command is essential for system monitoring and security auditing.
| Option | Description |
|---|---|
-n NUM |
Display only NUM lines of output |
-f FILE |
Read from specified log file instead of /var/log/wtmp |
-t DATE |
Display logins before specified date |
-s DATE |
Display logins since specified date |
-i |
Display IP addresses instead of hostnames |
-a |
Display hostname in last column |
-d |
Translate IP addresses to hostnames |
-x |
Display system shutdown and runlevel changes |
last username to show login history for a specific user. For example, last john will show all login sessions for the user 'john'.
lastb command to view failed login attempts. This reads from the /var/log/btmp file and shows unsuccessful login attempts, which is useful for security monitoring.
-s option to specify a start date and -t option for an end date. For example: last -s "2024-01-10" -t "2024-01-15" shows logins between those dates.