日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

防爆破登录:配置/etc/hosts.deny禁止ip尝试ssh或者telnet操作

發布時間:2023/12/31 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 防爆破登录:配置/etc/hosts.deny禁止ip尝试ssh或者telnet操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

買的tx云服務器,每天登錄上去就提示成千上萬條嘗試登錄記錄,看著就煩。于是找到個禁止ip登錄的方法。

/etc/hosts.allow和/etc/hosts.deny,這兩個文件中添加ip可以允許和禁止指定ip登錄。不過由于我登錄的ip是動態的,只能使用deny文件去禁止其他ip登錄。如果自己登錄的IP是固定的,可以直接在deny中配置sshd:all,再在allow中配置sshd:你的IP,這樣就只有你自己能登錄了,不用再擔心別人惡意爆破了。

配置如下

$ cat /etc/hosts.deny |head -n 20 # # hosts.deny This file contains access rules which are used to # deny connections to network services that either use # the tcp_wrappers library or that have been # started through a tcp_wrappers-enabled xinetd. # # The rules in this file can also be set up in # /etc/hosts.allow with a 'deny' option instead. # # See 'man 5 hosts_options' and 'man 5 hosts_access' # for information on rule syntax. # See 'man tcpd' for information on tcp_wrappers # sshd:209.141.35.3 sshd:45.61.188.131 sshd:137.184.7.179 sshd:178.62.3.183 sshd:91.215.137.38

默認修改就生效了的,不用重啟什么的操作。/etc/hosts.allow不配置就是允許所有IP。若配置了會先讀取allow文件,沒有匹配再讀取deny文件。

寫了個腳本,對嘗試登錄10次失敗的IP加入到deny文件中:

#!/bin/sh#登錄失敗次數大于10的ip IP=$(awk '/Failed/{print $(NF-3)}' /var/log/secure | sort |uniq -c |awk '{if($1>10) print $2}') hostdeny=/etc/hosts.denyfor i in $IP do#如果ip不存在,則寫入deny文件if [ ! $(grep $i $hostdeny) ];then echo "sshd:$i" >> $hostdenyfi done

登錄失敗的操作記錄可以在/var/log/secure日志文件中查看,也可以使用lastb命令查看。

$ lastb |head testing ssh:notty 47.103.112.43 Wed Feb 16 11:23 - 11:23 (00:00) jp ssh:notty 177.74.124.97 Wed Feb 16 11:23 - 11:23 (00:00) mi ssh:notty 1.117.157.44 Wed Feb 16 11:23 - 11:23 (00:00) jp ssh:notty 177.74.124.97 Wed Feb 16 11:23 - 11:23 (00:00) root ssh:notty 109.237.110.198 Wed Feb 16 11:23 - 11:23 (00:00) mi ssh:notty 1.117.157.44 Wed Feb 16 11:23 - 11:23 (00:00) summit ssh:notty 43.156.42.20 Wed Feb 16 11:23 - 11:23 (00:00) root ssh:notty 42.194.142.143 Wed Feb 16 11:23 - 11:23 (00:00) summit ssh:notty 43.156.42.20 Wed Feb 16 11:23 - 11:23 (00:00) paco ssh:notty 181.61.221.93 Wed Feb 16 11:23 - 11:23 (00:00)

總結

以上是生活随笔為你收集整理的防爆破登录:配置/etc/hosts.deny禁止ip尝试ssh或者telnet操作的全部內容,希望文章能夠幫你解決所遇到的問題。

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