2020-06-20第十一周

1、編寫(xiě)腳本/root/bin/checkip.sh,每5分鐘檢查一次,如果發(fā)現(xiàn)通過(guò)ssh登錄失敗 次數(shù)超過(guò)10次,自動(dòng)將此遠(yuǎn)程IP放入Tcp Wrapper的黑名單中予以禁止防問(wèn)

編寫(xiě)簡(jiǎn)本
#bin/bash
source /etc/profile 初始化環(huán)境變量

lastb |awk '{ip[$3]++}END{for(i in ip){if(ip[i]>10)print i }}' > /data/shell/ip.txt
while read ip
 do
   iptables -A INPUT -s $ip -j REJECT
   echo $ip
 done < /data/shell/ip.txt
設(shè)置定時(shí)任務(wù)
[root@centos7 shell]#crontab -e                                                                   
*/5  * * * * /bin/bash /data/shell/checkip.sh
[root@centos7 shell]# iptables -L -n 
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:53
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:53
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:67
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:67
REJECT     all  --  172.16.100.62        0.0.0.0/0            reject-with icmp-port-unreachable 被攔截ip
[root@et-server-62 ~]# ssh 172.16.100.43
ssh: connect to host 172.16.100.43 port 22: Connection refused 已無(wú)法訪問(wèn)

2、配置magedu用戶的sudo權(quán)限,允許magedu用戶擁有root權(quán)限

[root@centos7 ~]#su magedu   未授權(quán)時(shí)
[magedu@centos7 root]$sudo ls
[sudo] password for magedu: 
magedu is not in the sudoers file.  This incident will be reported
[root@centos7 ~]#visudo   更改配置文件
## Next comes the main part: which users can run what software on 
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
##      user    MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere 
root    ALL=(ALL)       ALL
magedu  ALL=(root)      ALL            賦予root權(quán)限
[root@centos7 ~]#su magedu
[magedu@centos7 root]$sudo ls
[sudo] password for magedu:  可查看
anaconda-ks.cfg  Documents  id_rsa_2048.pub  Music     Public          sudoers    Videos
Desktop      Downloads  ip.txt       Pictures  root@172.16.100.46  Templates

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容