Check the online server log today/var/log/secure found a lot of foreign IP attempts to log on to the server, has not been much attention to this aspect, as a system administrator is a dereliction of duty ah, although the server has set a strong password, but see someone want to engage you still very uncomfortable. At the beginning of the idea is through the firewall, and then Google to have a more simple than the firewall of the method, that is, through the/etc/hosts.deny configuration file can be banned some IP, the code is as follows:
#!/bin/bashCat/var/log/secure|awk'/failed/{print $ (NF-3)}'|sort|uniq-c|awk'{print $ = "$";}'>/root/black.txtcounts="2" forIteminch' cat/root/black.txt ' do IP= ' echo $item | awk-f='{print $}'' NUM= ' echo $item | awk-f='{print $}'` if[$NUM-gt $Counts];then grep $IP/etc/hosts.deny >/dev/NULLif[ $? -GT 0];then Echo"sshd: $IP:d eny">>/etc/Hosts.deny fi fidone
Not to be continued ....
Disable illegal IP login server