Clear or Remove Linux Logins History Information



Do you want to view or delete the last log on your Linux server? Then this article is for you. In it we will try to tell in detail and show the commands that you need to use, as well as check the result of your actions.

You need to know that there are three standard commands for Linux systems that show information about the most recently connected users: last, lastb and lastlog. The output of these commands includes: login, time of last connection , IP address, port, etc.

If you want to preserve anonymity, it is necessary to clear the history of recent connections.

Checking last login history


Checking last login history

First, you need to check the last login history. To do this, you need to enter one of the following commands, which will show login attempts, as well as the login history of the Linux system.

Command Log Description
last /var/log/wtmp Lists successful login/logout history
lastb /var/log/btmp History of failed login attempts
lastlog var/log/lastlog List of the last connected users
Also a popular request is how to clear the lastlog file in linux history.


Check last logged users


Check last logged users

You need to use commands last and lastb below

last


or

lastb


As we mentioned above, last uses /var/log/wtmp, and lastb /var/log/btmp. Now in order to clear wtmp/btmp, you need to use the following commands:

/var/log/wtmp


/var/log/btmp



Remove information about last login in Linux:


Remove information about last login in Linux

For removing all the information about the last logged in users, you need to clear the logs: (root required):

echo > /var/log/wtmp


echo > /var/log/btmp


echo > /var/log/lastlog


Removing last login information for exact users account:


This example command is suitable for those who need to delete the last log for a specific user.

sudo lastlog --clear --user username


username - you must specify the name of the user for whom you want to delete the last log

If you want to check that everything is done correctly, you need to use the commands below:

lastlog


lastlog --user username


If you need to clear the entire last log for all regular users:


sudo lastlog --clear --user 1000-



Conclusion


In this article, we examined in detail what last, lastb and lastlog are. What are they used for, how to check recent logins to your Linux system, indicating login time, name, IP address, etc., as well as displaying login attempts. We hope our article helped you in resolving your issue.