/var/log/lastlog: Explanation & Insights

Contains login session details

The file /var/log/lastlog is a system log file that records the details of the last login session of each user on a Linux system. This can include information such as username, login date and time, login duration, and the remote host from which the user logged in. The file is maintained by the system and updated automatically each time a user logs in.

Importance of /var/log/lastlog

Understanding the /var/log/lastlog file can be beneficial for several reasons:

  1. Security: By monitoring the /var/log/lastlog file, you can keep an eye on any unauthorized or suspicious login activities. Sudden changes in login patterns can indicate potential security threats.
  2. Troubleshooting: If a user is experiencing issues with logging in, the /var/log/lastlog file can provide insights into the problem. For example, it can help determine if the issue is related to a specific user account or a wider system problem.
  3. Usage Monitoring: Some organizations have policies regarding the use of their systems. The /var/log/lastlog file can help enforce these policies by providing data on when and how often users are logging in.

Reading /var/log/lastlog

To view the content of the /var/log/lastlog file, use the lastlog command. This command reads the /var/log/lastlog file and presents its content in a human-readable format.

Here is an example of how to use the command:

sudo lastlog

This will output a list of all users and their last login information. The output will look something like this:

Username         Port     From             Latest
root             pts/1    Mon Feb 15 10:12:34 -0500 2021
john             pts/2    Tue Feb 16 11:13:35 -0500 2021

Common Problems and Solutions

There are several issues that can be diagnosed and solved with the /var/log/lastlog file. For example, if a user complains about not being able to log in, you can use the lastlog command to check if the system is recognizing their login attempts.

Another common issue is the log rotation problem. Log files, including /var/log/lastlog, can become very large over time and take up a significant amount of disk space. To solve this, you can configure log rotation settings to archive or delete old entries in the /var/log/lastlog file.


The /var/log/lastlog file is a valuable tool for monitoring and troubleshooting login activity on a Linux system. By understanding what this file is and how to use it, you can enhance your system's security, troubleshoot login issues, and enforce system usage policies.

Except where otherwise noted, content on this site is licensed under a CC BY-SA 4.0 license CC BY SA