十一、Linux shell指令碼(IP訪問禁用與使用者賦權)
阿新 • • 發佈:2020-12-24
1.編寫指令碼/root/bin/checkip.sh,每5分鐘檢查一次,如果發現通過ssh登入失敗 次數超過10次,自動將此遠端IP放入Tcp Wrapper的黑名單中予以禁止防問
[root@localhost /data]#cat /data/checkip.sh #!/bin/bash #******************************************************************** #Author: Kevin.Wen #Revision: 1.0 #QQ: 2510905014 #Date: 2020-12-24 #FileName: checkip.sh #******************************************************************** n=10 cat /var/log/secure |grep sshd|awk '/Failed/{print $(NF-3)}'|sort |uniq -c|sort >>ssherro.log while read count ip;do if [ ${count} > ${n} ];then echo "sshd is from:${ip}" >> /etc/hosts.deny fi done < ssherro.log [root@localhost /data]#crontab -l */5 * * * * root /data/checkip.sh &> /dev/null
2.配置magedu使用者的sudo許可權,允許magedu使用者擁有root許可權
[root@localhost ~]#visudo
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
magedu ALL=(ALL) ALL ##新增該行。