日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

[Linux] Centos DenyHosts 禁止针对linux sshd的暴力破解

發布時間:2025/4/16 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [Linux] Centos DenyHosts 禁止针对linux sshd的暴力破解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

DenyHosts介紹:

當linux服務器暴露在互聯網之中,該Linux服務器將會遭到互聯網上的掃描軟件進行掃描,并試圖猜測SSH登錄口令的危險。而DenyHosts是Python語言寫的一個程序,它會分析sshd的日志文件(/var/log/secure),當發現重 復的攻擊時就會記錄IP到/etc/hosts.deny文件,從而達到自動屏IP的功能。

DenyHosts安裝:

DenyHosts 需要 Python v2.3或者更高版本支持。

1.Yum 安裝:

1 <span style="font-family: tahoma, arial, helvetica, sans-serif;">[root@DaoBiDao ~]# yum install -y denyhosts</span>

2.RPM安裝:

1 2 <span style="font-family: tahoma, arial, helvetica, sans-serif;">[root@DaoBiDao ~]# wget cache.ali.dagaiba.com/DenyHosts/DenyHosts-2.6-1.src.rpm [root@DaoBiDao ~]# rpm -ivh DenyHosts-2.6-1.src.rpm</span>

3.壓縮包安裝

1 2 3 4 5 <span style="font-family: tahoma, arial, helvetica, sans-serif;">[root@DaoBiDao~]# yum install python [root@DaoBiDao~]# wget cache.ali.dagaiba.com/DenyHosts/DenyHosts-2.6.tar.gz [root@DaoBiDao~]# tar -zxvf DenyHosts-2.6.tar.gz [root@DaoBiDao~]# cd DenyHosts-2.6 [root@DaoBiDao~]# python setup.py install</span>

?DenyHosts配置:

1 2 [root@DaoBiDao~]# cd /usr/share/denyhosts/ [root@DaoBiDao~]# cp denyhosts.cfg-dist denyhosts.cfg

編輯denyhosts.cfg配置文件

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 SECURE_LOG =?/var/log/secure #ssh 日志文件,它是根據這個文件來判斷的。 HOSTS_DENY =?/etc/hosts.deny #控制用戶登陸的文件 PURGE_DENY = 5m #過多久后清除已經禁止的,這里代表是5分鐘。 PURGE_THRESHOLD = 0 #默認0代表拒絕的主機可以被清除/重新添加無限期 BLOCK_SERVICE? = sshd #禁止的服務名 DENY_THRESHOLD_INVALID = 5 #允許無效用戶失敗的次數 DENY_THRESHOLD_VALID = 3 #允許普通用戶登陸失敗的次數 DENY_THRESHOLD_ROOT = 3 #允許root登陸失敗的次數 DENY_THRESHOLD_RESTRICTED = 1 #允許在$WORK_DIR/hosts-restricted里面出現的用戶失敗的次數 WORK_DIR =?/usr/share/denyhosts/data #將deny的host或ip紀錄到Work_dir中 SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES HOSTNAME_LOOKUP=YES #是否做域名反解 LOCK_FILE =?/var/lock/subsys/denyhosts #將DenyHOts啟動的pid紀錄到LOCK_FILE中,已確保服務正確啟動,防止同時啟動多個服務。 ADMIN_EMAIL = #設置管理員郵件地址 SMTP_HOST = localhost SMTP_PORT = 25 SMTP_USERNAME = foo SMTP_PASSWORD = bar SMTP_FROM = DenyHosts <nobody@localhost> SMTP_SUBJECT = DenyHosts Report SMTP_DATE_FORMAT = %a, %d %b %Y %H:%M:%S %z #設置發送郵件服務信息 SYSLOG_REPORT = YES #是否將denyhosts信息輸如到系統日志 ALLOWED_HOSTS_HOSTNAME_LOOKUP=YES #是否做主機名泛解析 AGE_RESET_VALID=5d #有效用戶登錄失敗計數歸零的時間 AGE_RESET_ROOT=25d #root用戶登錄失敗計數歸零的時間 AGE_RESET_RESTRICTED=25d #用戶的失敗登錄計數重置為0的時間 AGE_RESET_INVALID=10d #無效用戶登錄失敗計數歸零的時間 RESET_ON_SUCCESS =?yes #如果一個ip登陸成功后,失敗的登陸計數是否重置為0 DAEMON_LOG =?/var/log/denyhosts #denyhosts的日志文件 DAEMON_LOG_TIME_FORMAT = %b %d %H:%M:%S #denyhosts的日志文件時間格式 DAEMON_LOG_MESSAGE_FORMAT = %(asctime)s - %(name)-12s: %(levelname)-8s %(message)s #denyhosts的日志文件內容格式 DAEMON_SLEEP = 30s DAEMON_PURGE = 1h #該項與PURGE_DENY設置成一樣,設置是清除hosts.denied ssh用戶的時間 設置denyhosts啟動腳本
1 2 3 4 5 6 7 [root@DaoBiDao denyhosts]# cp daemon-control-dist daemon-control [root@DaoBiDao denyhosts]# chown root daemon-control [root@DaoBiDao denyhosts]# chmod 700 daemon-control [root@DaoBiDao denyhosts]# cp /usr/share/denyhosts/daemon-control /etc/init.d/denyhosts [root@DaoBiDao denyhosts]# chkconfig --add denyhosts [root@DaoBiDao denyhosts]# chkconfig --level 2345 denyhosts on [root@DaoBiDao denyhosts]# service denyhosts start

使用其他主機登錄,輸入多次錯誤的密碼就可以在/etc/hosts.deny查看到禁止的ip地址。

轉載于:https://my.oschina.net/notbad/blog/338545

總結

以上是生活随笔為你收集整理的[Linux] Centos DenyHosts 禁止针对linux sshd的暴力破解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。