linux伺服器下通過iptables+Denyhost抵禦暴力破解的配置方法_Linux

來源:互聯網
上載者:User

使用iptables 現在每分鐘串連ssh的次數

#允許本地環回介面訪問

iptables -A INPUT -i lo -j ACCEPT

#對已經建立的所有連結都允許存取

iptables -A INPUT -m state –state ESTABLISHED -j ACCEPT

#每分鐘對ssh的新串連只允許兩個,已建立的串連不限制

複製代碼 代碼如下:

iptables -A INPUT -p tcp –dport 22 -m limit –limit 2/minute –limit-burst 2 -m state –state NEW -j ACCEPT

#添加預設策略拒絕所有

iptables -P INPUT DROP

使用Denyhost 對錯誤的ssh密碼的ip進行拒絕訪問

下載denyhost http://sourceforge.net/projects/denyhosts/files/

安裝denyhost

tar -zxvf DenyHosts-2.6.tar.gzcd DenyHosts-2.6python setup.py install             #安裝DenyHostscd /usr/share/denyhosts/            #預設安裝路徑cp denyhosts.cfg-dist denyhosts.cfg        #denyhosts.cfg為設定檔cp daemon-control-dist daemon-control      #daemon-control為啟動程式chown root daemon-control           #添加root許可權chmod 700 daemon-control           #修改為可執行檔ln -s /usr/share/denyhosts/daemon-control /etc/init.d  #對daemon-control進行軟串連,方便管理/etc/init.d/daemon-control start   #啟動denyhostschkconfig daemon-control on    #將denghosts設成開機啟動

配置denyhost

vim /usr/share/denyhosts/denyhosts.cfgHOSTS_DENY = /etc/hosts.deny     #控制使用者登陸的檔案PURGE_DENY = 30m         #過多久後清除已經禁止的,設定為30分鐘;BLOCK_SERVICE = sshd       #禁止的服務名,當然DenyHost不僅僅用於SSH服務DENY_THRESHOLD_INVALID = 1    #允許無效使用者失敗的次數DENY_THRESHOLD_VALID = 5     #允許普通使用者登陸失敗的次數DENY_THRESHOLD_ROOT = 5     #允許root登陸失敗的次數DAEMON_LOG = /var/log/denyhosts  #DenyHosts記錄檔存放的路徑,預設

更改DenyHosts的預設配置之後,重啟DenyHosts服務即可生效:

/etc/init.d/daemon-control restart   #重啟denyhosts

轉自:http://www.zhengdazhi.com/?p=563

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.