How to check the information of users who have logged in in the past in Linux

08-01-2023

This article mainly introduces how to view the information of users who have logged in in the past in Linux. In daily operations, I believe that many people have doubts about how to view the information of users who have logged in in the past in Linux. This is a useful operation method, and I hope it will help you to answer your doubts about how to check the information of users who have logged in in the past in Linux! Next, please follow the editor to learn together!

How to view past login user information in linux: 1. Use the last command to view the current and past login system user related information, syntax last [option]; 2. Use the lastlog command to view the last login time of users who have logged in to the current system. The last command reads the /var/log/wtmp log file by default, and the lastlog command reads the /var/log/lastlog file by default. These two files are binary files and cannot be edited directly with vi.

In Linux, you can use the w or who command to view the user information currently logged in to the system, but if the user who logged in before has logged out now, can you still view it? Of course you can, which requires the use of the last and lastlog commands.

linux last command

last command can view the current and past login system user information;

the basic format of the last command As follows:

[root@localhost ~]# last [option]

Table 1 Lo Commonly used options and meanings of this command are listed.

Table 1 Commonly used options and meanings of the last command
OptionsMeaning
-aDisplay the hostname or IP address from where the system is logged in on the last line.
-RDo not display the hostname or IP address of the logged-in system.
-xDisplay information such as system shutdown, restart, and execution level changes.
-n number of display columnsSet the number of display columns to list information.
-dConvert the displayed IP address to a hostname.

When the last command is executed, it will read the /var/log/wtmp log file by default. This is a binary file, which cannot be edited directly with vi, but can only be called by the last command .

Example: Query current and past logged in user information

[root@localhost ~]# last root pts/0 192.168.0.108 Fri Jun 7 09:53 still logged in root tty1 Fri Jun 7 09:53 still logged in root pts/0 192.168.0.101 Fri Jun 7 06:53 - 09:52 (02:59) root pts/1 192.168.0.103 Fri Jun 7 04:12 - 04:30 (00:18) #username login terminal login IP login time - logout time (online time) reboot system boot 2.6.32-279.el6.i Thu Jun 6 23:53 - 00:03 (00:09) # You can also see the system restart time ...Omit part of the output...

linux lastlog command

lastlog command can view the latest login system of each system user time. For example:

[root@localhost ~]#lastlog #username port from last login time Username Port From Latest root pts/1 192.168.1.100 Wed Mar 4 11:04:22 +0800 2009 bin **Never logged in** ....(omitted in the middle).... vbird1 pts/2 192.168.1.100 Wed Mar 4 13:15:56 +0800 2009 ....(omitted below)....

laThe stlog command defaults to read the /var/log/lastlog log file. This file is also a binary file and cannot be edited directly with vi. It needs to be invoked with the lastlog command.

At this point, the study on how to check the information of users who have logged in in the past in Linux is over, and I hope to solve your doubts. The combination of theory and practice can better help you learn, go try it! If you want to continue to learn more relevant knowledge, please continue to pay attention to the Yisuyun website, and the editor will continue to work hard to bring you more practical articles!

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us