linux使用/etc/hosts.deny拒绝恶意ssh到本机

一、目标

在某些特殊情况下,服务器有很多恶意暴力ssh破解的攻击。解决的办法有很多,这里用/etc/hosts.deny增加黑名单的方式来简单阻止一下。

二、前言

/etc/hosts.allow 优先于 /etc/hosts.deny。

如果在allow和deny文件中都有某个ip,那么这个ip是被允许ssh。

如果在allow中有,deny没有,那么这个ip是被允许ssh。

如果allow中没有,deny有,那么这个ip是被禁止ssh。

还可以在 /etc/hosts.deny文件里追加一个额外配置,让其读取另外一个ip列表。这样可以使你以后维护需要禁止的ip更方便

三、 /etc/hosts.deny的使用方法

1、方法1:

     直接在 /etc/hosts.deny文件里写拒绝规则

echo "sshd: 10.0.1.29" >> /etc/hosts.deny
2、方法2:

     在 /etc/hosts.deny文件写一个额外读取ip列表的规则

echo "sshd: /etc/sshd.deny.hostguard"   >> /etc/hosts.deny'
echo "10.0.1.29" >> /etc/sshd.deny.hostguard

注:以后就往sshd.deny.hostguard里面写恶意ip的地址就行了。保持一行一个ip。

四、(附)看哪些ip在恶意访问

tail -f /var/log/secure
tail -n 100 /var/log/secure |grep 'Failed password' |egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}'
lastb -n 500 |awk '{print $3}' |sort |uniq |egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}'

 

 注意检查别有自己ip被写进去了

----------------------2024年5月11日09:21:49--------------------

相关推荐

  1. linux使用/etc/hosts.deny拒绝恶意ssh

    2024-05-13 06:04:06       32 阅读
  2. SSH连接虚拟拒绝

    2024-05-13 06:04:06       20 阅读
  3. 使用uniapp完成微信小程序的图片下载

    2024-05-13 06:04:06       64 阅读
  4. linux查看ip地址

    2024-05-13 06:04:06       61 阅读
  5. CentOS服务器拒绝SSH登录

    2024-05-13 06:04:06       57 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-13 06:04:06       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-13 06:04:06       106 阅读
  3. 在Django里面运行非项目文件

    2024-05-13 06:04:06       87 阅读
  4. Python语言-面向对象

    2024-05-13 06:04:06       96 阅读

热门阅读

  1. [力扣题解]406. 根据身高重建队列

    2024-05-13 06:04:06       31 阅读
  2. LeetCode刷题笔记之图论

    2024-05-13 06:04:06       24 阅读
  3. Redis 本机无法访问

    2024-05-13 06:04:06       31 阅读
  4. conda 常用20个命令

    2024-05-13 06:04:06       32 阅读
  5. SQLite 命令

    2024-05-13 06:04:06       36 阅读