The lastlog
command is a Linux utility that displays the last login information of all users in the system. It reads the /var/log/lastlog
file and displays the information in a human-readable format. This command is useful for system administrators who want to keep track of user activity on a system.
Overview
To use the lastlog
command, simply enter lastlog
in the terminal. This will display the last login information for all users on the system. The output includes the username, the port or device name used for the login, the date and time of the last login, and the location of the login.
Here is an example output of the lastlog
command:
Username Port From Latest
root **Never logged in**
daemon **Never logged in**
bin **Never logged in**
sys **Never logged in**
sync **Never logged in**
games **Never logged in**
man **Never logged in**
lp **Never logged in**
mail **Never logged in**
news **Never logged in**
uucp **Never logged in**
proxy **Never logged in**
www-data **Never logged in**
backup **Never logged in**
list **Never logged in**
irc **Never logged in**
gnats **Never logged in**
nobody **Never logged in**
systemd-timesync **Never logged in**
systemd-network **Never logged in**
systemd-resolve **Never logged in**
systemd-bus-proxy **Never logged in**
_apt **Never logged in**
Options
The lastlog
command has the following options:
Option | Description |
---|---|
-b , --before DAYS |
Display only entries older than DAYS. |
-h , --help |
Display help message and exit. |
-t , --time DAYS |
Display only entries more recent than DAYS. |
-u , --user LOGIN |
Display only information for the specified LOGIN. |
Troubleshooting tips
If the lastlog
command does not display any information, it may be because the /var/log/lastlog
file does not exist. This file is created by the logrotate
utility, which rotates log files on a system. If the logrotate
utility is not configured to rotate the lastlog
file, it may not exist.
To troubleshoot this issue, check the /etc/logrotate.conf
file and ensure that the lastlog
file is included in the list of log files to be rotated. If it is not, add it to the list and run the logrotate
command manually to create the file.
Notes
- The
lastlog
command requires root privileges to run. - The
lastlog
command only displays information for users who have logged in at least once. - The
lastlog
command displays information in reverse chronological order, with the most recent login at the top of the list.