---
title: "linux监控命令"
author: "andyniu"
date: "2015-04-10T08:44:35Z"
tags: []
categories: ["操作系统"]
slug: "linux"
draft: false
lastmod: "2015-04-10T15:19:32Z"
id: 2200817
url: "https://andyniu.iteye.com/blog/2200817"
---

1、监控ssh访问IP

 netstat -ntp |grep sshd

2、查看最近登录用户

last

3、查看访问日志

 more /var/log/secure

 

 

 

 

监控脚本，可以监控ssh暴力，如果输入错误密码超过5次  则禁止ssd登录

#! /bin/bash  
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' &gt; /root/black.txt  
DEFINE="5"  
for i in \`cat  /root/black.txt\`  
do  
    IP=\`echo $i |awk -F= '{print $1}'\`  
    NUM=\`echo $i|awk -F= '{print $2}'\`  
    if \[ $NUM -gt $DEFINE ]  
    then  
      grep $IP /etc/hosts.deny &gt; /dev/null  
      if \[ $? -gt 0 ]  
      then  
          echo $IP  
          echo "sshd:$IP:deny" &gt;&gt; /etc/hosts.deny  
      fi  
    fi  
done

 以上脚本可以配合/etc/hosts.deny和/etc/hosts.allow这两个文件一起使用