设为首页收藏本站language→→ 语言切换

鸿鹄论坛

 找回密码
 论坛注册

QQ登录

先注册再绑定QQ

查看: 628|回复: 1
收起左侧

使用DenyHosts防止ssh暴力破解

[复制链接]
发表于 2021-6-5 15:38:14 | 显示全部楼层 |阅读模式
DenyHosts是用python2.3编写的一个程序,会分析/var/log/secure等文件,当发现同一个ip进行多次ssh登录失败时会将其写入/etc/hosts.dengy文件,达到屏蔽该ip的目的。


                               
登录/注册后可看大图

下载DenyHosts包
[root@localhost ~]# wget http://jaist.dl.sourceforge.net/ ... enyHosts-2.6.tar.gz安装DenyHosts
[root@localhost ~]# tar xf DenyHosts-2.6.tar.gz[root@localhost ~]# cd DenyHosts-2.6[root@localhost DenyHosts-2.6]# python setup.py install制作配置文件
[root@localhost DenyHosts-2.6]# cp denyhosts.cfg-dist /etc/denyhosts.cfg[root@localhost DenyHosts-2.6]# cp daemon-control-dist daemon-control[root@localhost DenyHosts-2.6]# chown root daemon-control[root@localhost DenyHosts-2.6]# chmod 700 daemon-control修改配置文件

将daemon-control中的#DENYHOSTS_CFG = "/usr/share/denyhosts/denyhosts.cfg"改为 DENYHOSTS_CFG = "/etc/denyhosts.cfg"


                               
登录/注册后可看大图

启动
[root@localhost DenyHosts-2.6]# ./daemon-control start(注意相对路径)测试另外一台服务器远程连接172.16.1.16

默认允许五次,测试发现登陆失败五次之后不允许登陆

[root@localhost ~]# ssh abc@172.16.1.16abc@172.16.1.16's password: Permission denied, please try again.abc@172.16.1.16's password: Permission denied, please try again.abc@172.16.1.16's password: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).[root@localhost ~]# [root@localhost ~]# ssh abc@172.16.1.16abc@172.16.1.16's password: Permission denied, please try again.abc@172.16.1.16's password: Permission denied, please try again.abc@172.16.1.16's password: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).[root@localhost ~]# ssh abc@172.16.1.16abc@172.16.1.16's password: Permission denied, please try again.abc@172.16.1.16's password: Permission denied, please try again.abc@172.16.1.16's password: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).[root@localhost ~]# ssh abc@172.16.1.16abc@172.16.1.16's password: Permission denied, please try again.abc@172.16.1.16's password: Permission denied, please try again.abc@172.16.1.16's password: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).[root@localhost ~]# ssh abc@172.16.1.16ssh_exchange_identification: read: Connection reset by peer查看hosts.deny文件

登陆连续失败之后就会把ip地址写在hosts.deny文件


                               
登录/注册后可看大图

172.16.1.112的ip已经被限制,到此功能实现。


您需要登录后才可以回帖 登录 | 论坛注册

本版积分规则

QQ|Archiver|手机版|小黑屋|sitemap|鸿鹄论坛 ( 京ICP备14027439号 )  

GMT+8, 2024-4-25 01:38 , Processed in 0.056147 second(s), 8 queries , Redis On.  

  Powered by Discuz!

  © 2001-2024 HH010.COM

快速回复 返回顶部 返回列表