1、编写脚本/root/bin/checkip.sh,每5分钟检查一次,如果发现通过ssh登录失败 次数超过10次,自动将此远程IP放入Tcp Wrapper的黑名单中予以禁止防问
[root@centos7 bin]#cat checkip.sh
#!/bin/bash
touch /etc/hosts.deny
lastb | awk '/ssh/{IP[$3]++}END{for(n in IP){if(IP[n]>2){system("echo 'sshd:'" n ":deny >> /etc/hosts.deny")}}}'
grep '^#' /etc/hosts.deny > /etc/hosts.deny.tmp
grep -v "^#" /etc/hosts.deny | sort -u >> /etc/hosts.deny.tmp
cat /etc/hosts.deny.tmp > /etc/hosts.deny
rm -f /etc/hosts.deny.tmp
[root@centos7 bin]#crontab -l
*/5 * * * * /bin/bash /root/bin/checkip.sh
2、配置magedu用户的sudo权限,允许magedu用户拥有root权限
# 使用visudo,添加下面一行
[root@centos7 ~]#visudo
magedu ALL=(root) ALL
# 验证效果
[root@centos7 ~]#su - magedu
Last login: Sat Jul 4 12:40:52 CST 2020 on pts/2
# 使用sudo才可以访问/root目录
[magedu@centos7 ~]$ls /root
ls: cannot open directory /root: Permission denied
[magedu@centos7 ~]$sudo ls /root
anaconda-ks.cfg bin create.sh expect2.sh expect3.sh expect.sh hellodb_innodb.sql initial-setup-ks.cfg