systemctl restart sshd.service sudo nmap -Pn -sS 192.168.224.*/24
ssh root@192.168.224.131 -p 2222
登录几次失败我们可以测下
sudo lastb
我们登录失败的次数都被记录在这上面。
sudo cat /var/log/btmp
lastlog
最后一次登录的IP
cat /var/log/lastlog
cat /var/log/secure |awk '/Failed/{print $(NF-3)}' |sort |uniq -c |awk '{print $2"="$1;}' >/usr/local/bin/black.list for i in `cat /usr/local/bin/black.list` do IP=`echo $i |awk -F= '{print $1}'` NUM=`echo $i |awk -F= '{print $2}'` if [ ${#NUM} -gt 1 ]; then grep $IP /etc/hosts.deny >/dev/null if [ $? -gt 0]; then echo "sshd:$IP:deny" >>/etc/hosts.deny echo -e "$IP \c" fi fi done echo "is denied now."这段代码里的 /var/log/secure目前在ubuntu20.4里没有自带有所以修改下代码 OK这篇是centOS服务器的脚本 由于我用的是PC端的Ubuntu所以得修改部分代码
su root mkdir /script touch /script/checkBlackIp.sh chmod 755 /script/checkBlackIp.sh /script chown root:root /script/checkBlackIp.sh vim /script/checkBlackIp.sh
加入下面代码
#!/bin/sh lastb |awk '/ssh/{print $3}' |sort |uniq -c |awk '{print $2"="$1}' >/script/black.list for i in `cat /script/black.list` do IP=`echo $i |awk -F= '{print $1}'` NUM=`echo $i |awk -F= '{print $2}'` if [ ${#NUM} -ne 1 ]; then grep $IP /etc/hosts.deny >/dev/null if [ ! $? -eq 0 ]; then echo "sshd:$IP:deny" >>/etc/hosts.deny echo "$IP \c" fi fi done echo "is denied now."
crontab -e
vim /etc/crontab
systemctl restart cron.service systemctl enable cron.service
https://www.cnblogs.com/eternalnight/p/13905048.html