


This article mainly shares with you a summary of the last and lastb commands in the Linux environment. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.
1. Background
This morning I saw an article about a server being cracked and used as a mining machine. In the article, I saw that the author used the lastb command to find the attacker's login history. I thought it was quite powerful, so I summarized the commands related to last and lastb.
2. Last command
1. Function:
The last command is used to display the user’s recent login information. Execute the last command alone, it will read the /var/log/wtmp file and display the list of all users logged into the system recorded in the file. Successful login information.
2. Command parameters:
-a:把从何处登入系统的主机名称或ip地址,显示在最后一行; -d:将IP地址转换成主机名称; -f <记录文件>:指定记录文件。 -n <显示列数>或-<显示列数>:设置列出名单的显示列数; -R:不显示登入系统的主机名称或IP地址; -x:显示系统关机,重新开机,以及执行等级的改变等信息。
3. Expression form
4. Explanation
第一列:用户名 第二列:终端位置 第三列:登录ip或者内核 第四列:开始时间 第五列:结束时间(still login in 还未退出 down 直到正常关机 crash 直到强制关机) 第六列:持续时间
wtmp, btmp, and utmp are all binary files. They cannot be viewed with cat and can be opened with last.
2. lastb command
1. Function:
The Linux lastb command is used to list information about users who failed to log in to the system. Execute the lastb command alone, it will read the file named btmp located in the /var/log directory, and display all the login failed user lists recorded in the file.
2. Parameters
-a 把从何处登入系统的主机名称或IP地址显示在最后一行。 -d 将IP地址转换成主机名称。 -f<记录文件> 指定记录文件。 -n<显示列数>或-<显示列数> 设置列出名单的显示列数。 -R 不显示登入系统的主机名称或IP地址。 -x 显示系统关机,重新开机,以及执行等级的改变等信息。
3. Main log files under linux
1. 进程日志(acct/pacct: 记录用户命令) 2. 错误日志(/var/log/messages:系统级信息;access-log:记录HTTP/WEB的信息) 3. 连接日志(/var/log/wtmp,/var/log/btmp,/var/run/utmp) >>>有关当前登录用户的信息记录在文件utmp中; >>>登录进入和退出纪录在文件wtmp中; >>>最后一次登录文件可以用lastlog命令察看; >>>数据交换、关机和重起也记录在wtmp文件中;
3. How to clear user login Information
Since you can use last and other commands to view the records of successful logins, natural entrants can also use some means to clear these records.
1. Clear login success information
清除登陆系统成功的记录 [root@localhost root]# echo > /var/log/wtmp //此文件默认打开时乱码,可查到ip等信息 [root@localhost root]# last //此时即查不到用户登录信息
2. Clear login failure information
清除登陆系统失败的记录 [root@localhost root]# echo > /var/log/btmp //此文件默认打开时乱码,可查到登陆失败信息 [root@localhost root]# lastb //查不到登陆失败信息
3. Clear historical executed commands
清除历史执行命令 [root@localhost root]# history -c //清空历史执行命令 [root@localhost root]# echo > ./.bash_history //或清空用户目录下的这个文件即可
4. Import empty historical command files
导入空历史记录 [root@localhost root]# vi /root/history //新建记录文件 [root@localhost root]# history -c //清除记录 [root@localhost root]# history -r /root/history.txt //导入记录 [root@localhost root]# history //查询导入结果
Server security is also a top priority in daily development. I hope I can learn this aspect well. Although I haven’t been attacked yet, no one can predict what will happen in the future. Record it.
end
Related recommendations:
1. How to clear user login records and command history in Linux
2. In-depth understanding of last under Linux Commands and their data sources
The above is the detailed content of Summarize the last and lastb commands in Linux environment. For more information, please follow other related articles on the PHP Chinese website!

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools