Linux lastb command
Linux lastb The command is used to list information about users who failed to log in.
When the lastb command is run on its own, it reads the file located in /var/log directory, named btmp and displays all the usernames recorded as failed login attempts in that file.
Syntax
lastb [-adRx][-f <记录文件>][-n <显示行数>][帐号名称...][终端机编号...]
Parameter Description:
options:
- -R omit the hostname column
- -a Display the hostname or IP address from which the user logged in on the last line.
- -d Convert IP addresses to hostnames.
- -f
Specify the record file. - -n
or - Specify the number of lines to display. - -R Do not display the hostname or IP address of the login.
- -x Display information about system shutdowns, reboots, and changes in run level.
username:
- username: display login information for the specified user username.
tty:
- tty sets the login terminal; the tty name can be abbreviated, so last 0 is the same as last tty0.
Example
Display information about users with failed logins:
# lastb
...
zgg ssh:notty 143.198.176.57 Thu Apr 7 11:27 - 11:27 (00:00)
zgg ssh:notty 143.198.176.57 Thu Apr 7 11:27 - 11:27 (00:00)
zf ssh:notty 143.198.176.57 Thu Apr 7 11:27 - 11:27 (00:00)
za ssh:notty 143.198.176.57 Thu Apr 7 11:27 - 11:27 (00:00)
zeng ssh:notty 143.198.176.57 Thu Apr 7 11:27 - 11:27 (00:00)
zf ssh:notty 143.198.176.57 Thu Apr 7 11:27 - 11:27 (00:00)
zette ssh:notty 143.198.176.57 Thu Apr 7 11:27 - 11:27 (00:00)
z310 ssh:notty 143.198.176.57 Thu Apr 7 11:27 - 11:27 (00:00)
btmp begins Fri Apr 1 07:38:45 2022
Display 5 lines of information about failed logins:
# lastb -n 5
mos ssh:notty 194.31.98.204 Thu Apr 28 16:52 - 16:52 (00:00)
user ssh:notty 194.31.98.204 Thu Apr 28 16:52 - 16:52 (00:00)
user ssh:notty 194.31.98.204 Thu Apr 28 16:52 - 16:52 (00:00)
user ssh:notty 194.31.98.204 Thu Apr 28 16:52 - 16:52 (00:00)
user ssh:notty 194.31.98.204 Thu Apr 28 16:52 - 16:52 (00:00)
btmp begins Fri Apr 1 07:38:45 2022
Linux Command Reference