Linux学习作业---第十二周(6.29-7.6)

一、编写脚本/root/bin/checkip.sh,每5分钟检查一次,如果发现通过ssh登录失败 次数超过10次,自动将此远程IP放入Tcp Wrapper的黑名单中予以禁止防问
vi /root/bin/checkip

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

二、配置magedu用户的sudo权限,允许magedu用户拥有root权限
vi /etc/sudoers

## Allow root to run any commands anywhere 
root    ALL=(ALL)   ALL
magedu  ALL=(ALL)   ALL

你可能感兴趣的:(Linux学习作业---第十二周(6.29-7.6))