Linux学习(十二)

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

vim /root/bin/checkip.sh

lastb | awk ‘! /^btmp|^$/{ip[$3]++}END{for(i in ip){if{(ip[i]>=10){if(system("grep "i" /etc/hosts.deny &> /dev/null")){system("echo sshd:"i">> /etc/hosts.deny")}}}}’

chmod +x checkip.sh
crontab -e

*/5 * * * *  /root/bin/checkip.sh &> /dev/null

2、配置magedu用户的sudo权限,允许magedu用户拥有root权限

visudo

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

原文地址:https://www.cnblogs.com/shanghongbin/p/13251754.html