小白学linux | 使用正则表达式审计ssh登录ip地址

Ubuntu /var/log/auth.log记录了所有与身份验证相关的事件,包括SSH登录尝试

复制代码
grep -i "failed password" /var/log/auth.log | \awk '{if($11 ~/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/)print $11 ; else print $13}' | \uniq -c | sort -nr -k1

RedHat系发行版 /var/log/secure 记录了与安全相关的事件,包括SSH登录

复制代码
grep -i "failed password" /var/log/secure | \awk '{if($11 ~/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/)print $11 ; else print $13}' | \uniq -c | sort -nr -k1

通过指定/var/log/wtmp文件,可以查看用户登录的详细信息,包括登录IP地址

复制代码
last -f /var/log/wtmp

lastlog 显示最近一次成功登录的信息,包括IP地址

复制代码
lastlog

实时查看当前登录用户的信息,包括IP地址

复制代码
who

Ubuntu 日志

复制代码
drwxrwxr-x  12 root      syslog             4096 Jun  5 06:25 ./
drwxr-xr-x  14 root      root               4096 Mar 12 17:12 ../
-rw-r--r--   1 root      root                  0 May 14 06:25 alternatives.log
drwxr-x---   2 root      adm                4096 Mar 14 06:25 apache2/
drwxr-xr-x   2 root      root               4096 Jun  1 06:25 apt/
-rw-r-----   1 syslog    adm             1858772 Jun  5 14:41 auth.log
-rw-r--r--   1 root      root                  0 Jul 13  2023 bootstrap.log
-rw-rw----   1 root      utmp            1723008 Jun  5 14:24 btmp
drwxr-xr-x   2 _chrony   _chrony            4096 Aug 26  2020 chrony/
-rw-r--r--   1 syslog    adm              212710 Mar 12 13:16 cloud-init.log
-rw-r--r--   1 root      root               9860 Mar 12 13:16 cloud-init-output.log
drwxr-xr-x   2 root      root               4096 Jun 20  2019 dist-upgrade/
-rw-r--r--   1 root      root                  0 Jun  1 06:25 dpkg.log
-rw-r--r--   1 root      root               3616 Apr 24 11:22 faillog
-rw-r--r--   1 root      root                352 May 13 11:22 fontconfig.log
drw-------   2 root      root               4096 Jun  5 06:37 hostguard/
drwxr-xr-x   3 root      root               4096 Jul 13  2023 installer/
drwxr-sr-x+  3 root      systemd-journal    4096 Jul 13  2023 journal/
-rw-r-----   1 syslog    adm                   0 Apr 24 06:25 kern.log
drwxr-xr-x   2 landscape landscape          4096 Mar 12 12:25 landscape/
-rw-rw-r--   1 root      utmp              32996 Jun  5 14:41 lastlog
drwxr-xr-x   2 root      root               4096 Nov 24  2018 lxd/
-rw-r--r--   1 root      root                558 Mar 12 13:16 multi-queue-hw.log
-rw-r-----   1 syslog    adm                4300 Jun  5 14:41 syslog
-rw-------   1 root      root               7232 Apr 24 11:22 tallylog
-rw-r--r--   1 root      root              19256 Jun  5 10:03 ubuntu-advantage.log
drwxr-x---   2 root      adm                4096 Apr  1 06:25 unattended-upgrades/
-rw-r-----   1 root      adm              161293 Jun  5 14:42 vsftpd.log
-rw-rw-r--   1 root      utmp               1152 Jun  5 14:41 wtmp
-rw-------   1 root      root                  0 Apr 10 13:40 yum.log
  • alternatives.log: 记录了通过 update-alternatives 命令管理符号链接的更改。
  • apache2/: 存储Apache Web服务器的日志文件,包括访问日志和错误日志。
  • apt/: 包含与APT包管理器相关的日志,如软件包安装和更新的详细信息。
  • auth.log: 记录了所有与身份验证相关的事件,包括成功和失败的登录尝试,以及其他身份验证活动。
  • btmp: 记录所有失败的登录尝试。使用 lastb 命令查看。
  • chrony/: 记录Chrony服务的日志,Chrony是一个时间同步服务。
  • cloud-init.log: 记录cloud-init服务的日志,cloud-init用于初始化云实例。
  • dpkg.log: 记录通过dpkg命令进行的包安装、删除和其他操作。
  • faillog: 记录失败的登录尝试的计数,可以通过 faillog 命令查看。
  • fontconfig.log: 记录Fontconfig库的日志,Fontconfig用于字体配置和定制。
  • hostguard/: 可能与一个特定的监控或安全软件相关的日志目录。
  • installer/: 记录系统安装过程的日志文件。
  • journal/: systemd的日志目录,包含二进制格式的系统日志。可以通过 journalctl 命令查看。
  • kern.log: 记录内核相关的日志信息,包括启动信息和内核错误。
  • landscape/: 记录与Landscape相关的日志,Landscape是Canonical提供的系统管理服务。
  • lastlog: 记录每个用户最后一次登录的时间,可以通过 lastlog 命令查看。
  • lxd/: 记录LXD容器管理器的日志。
  • multi-queue-hw.log: 记录与多队列硬件相关的日志信息。
  • syslog: 记录系统范围内的日志信息,包括应用程序和服务的日志。
  • tallylog: 记录PAM(Pluggable Authentication Modules)的登录尝试计数。
  • ubuntu-advantage.log: 记录Ubuntu Advantage服务的日志,Ubuntu Advantage提供企业级支持。
  • unattended-upgrades/: 记录自动软件包更新的日志。
  • vsftpd.log: 记录VSFTPD FTP服务器的日志,包括连接和传输信息。
  • wtmp: 记录所有用户登录和注销事件。可以通过 last 命令查看。
  • yum.log: 记录YUM包管理器的操作日志(适用于RedHat系系统)。
相关推荐
orion571 天前
Missing Semester Class1:course overview and introduction of shell
linux
用户120487221611 天前
Linux驱动编译与加载
linux·嵌入式
用户805533698031 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698031 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
七歌杜金房2 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
tntxia3 天前
linux curl命令详解_curl详解
linux
扛枪的书生3 天前
Linux 网络管理器用法速查
linux
顺风尿一寸3 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
XIAOHEZIcode3 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫4 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux