bash行,用于简单统计SSH中断尝试

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bash行,用于简单统计SSH中断尝试相关的知识,希望对你有一定的参考价值。

Assumes logs are in /var/log/sshd/* and makes a few text format assumptions that probably make this specific to OpenSSH.

Simple, but more than you can see from a quick less.
  1. # Amount per source IP:
  2. cat /var/log/sshd/* | grep 'Invalid'|rev|cut -d ' ' -f 1 | rev | sort | uniq -c | sort -n
  3.  
  4. # Amount per day:
  5. cat /var/log/sshd/* | grep 'Invalid' | tr -s ' ' | cut -d ' ' -f 1-2 | sort | uniq -c
  6.  
  7. # The usernames they try:
  8. cat /var/log/sshd/* | grep 'Invalid'|rev|cut -d ' ' -f 3| rev | sort | uniq -c | sort -r -n | less
  9.  
  10.  
  11. #The source IPs of accepted logins (to look for things not you)
  12. egrep 'Accepted (keyboard|publi)[^ ]+ for' /var/log/sshd/* |
  13. sed -r 's/(.*from[ ])([0-9.]+)([ ]port.*)/2'/ | sort | uniq -c | sort -n
  14.  
  15. # Same IP list, but with hostnames instead of counts
  16. # (assuming 'host' is your reverse lookup utility)
  17. egrep 'Accepted (keyboard|publi)[^ ]+ for' /var/log/sshd/* |
  18. sed -r 's/(.*from[ ])([0-9.]+)([ ]port.*)/2'/ | sort | uniq | xargs -n 1 host

以上是关于bash行,用于简单统计SSH中断尝试的主要内容,如果未能解决你的问题,请参考以下文章

当我中断 ssh 本身时,如何使 ssh 杀死远程进程?

统计代码行数的实用脚本

Linux ssh bash fork 重试:没有子进程

c_cpp 快速代码片段,用于在统计(阻止)/ dev / rdsk中的设备时验证fstat64和stat64的行为。

用于设置临时 SSH 隧道的 Bash 脚本

bash 一个用于计算 bash 中特定数字行的平均值的衬垫