DenyHosts の導入

2021-06-18

概要

ServersMan@VPSのEntryプラン を利用していますが、/var/log/secure をみるとSSHのログイン失敗のアクセスが増えてきました。root ログインはできない設定にしていますが気持ち悪いの対策をおこないます

# cat /var/log/secure|grep fail
Aug 23 17:01:57 localhost sshd[36130]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=XXX.XXX.XXX.XXX user=root
Aug 23 17:02:03 localhost sshd[36582]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=XXX.XXX.XXX.XXX user=root
Aug 23 17:02:10 localhost sshd[37928]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=XXX.XXX.XXX.XXX user=root

DenyHosts の導入

DenyHostsとは?

DenyHostsは不正な攻撃を察知して防御するためのツールです。
設定ファイルで指定した不正アクセスがが繰り返された場合に、そのIPアドレスを/etc/hosts.denyに記録し接続を拒否します。

(1)python インストール

DenyHosts を python が必要ですので、python をインストールします
自分の環境では、python は導入済ですが、python-devel が入ってないのでインストールします

# yum install python-devel

(2)DenyHosts のパッケージをダウンロード

denyhosts-2.6-7.el5.kb.noarch.rpm をダウンロードします。
パッケージは、RPM Search で検索して探しました

# cd /var/tmp
# wget ftp://ftp.pbone.net/mirror/centos.karan.org/el5/extras/testing/x86_64/RPMS/denyhosts-2.6-7.el5.kb.noarch.rpm

(3)DenyHosts インストール

先程、ダウンロードした DenyHostsのパッケージをインストールします

# rpm -Uvh denyhosts-2.6-7.el5.kb.noarch.rpm
Preparing... ########################################### [100%]
1:denyhosts ########################################### [100%]

(4)設定ファイルの編集

DenyHostsの設定ファイル(/etc/denyhosts.conf)を編集します
変更箇所のみ下記に記入しています

設定ファイルをバックアップします
# cp -p /etc/denyhosts.conf /etc/denyhosts.conf.org

設定ファイルを編集します
# vi diff /etc/denyhosts.conf

# 拒否を解除するまで期間 (6時間に設定)
PURGE_DENY = 6h

# 存在しないユーザログイン(/etc/passwd)でログイン失敗の閾値
DENY_THRESHOLD_INVALID = 3

# 存在するユーザログイン(/etc/passwd)でログイン失敗の閾値
DENY_THRESHOLD_VALID = 5

# イベントメールの送信先
ADMIN_EMAIL = xxxx@xxxx.com

# イベントメールの送信元
SMTP_FROM = DenyHosts <xxxx@xxxx.com>

(5)hosts.allow の編集

契約しているISP経由での SSH をhosts.allow に追加

# vi /etc/hosts.allow
ALL: 127.0.0.1
# gyao
sshd: .XXXX.ne.jp

(6)DenyHosts 自動起動の設定

DenyHosts を起動と自動起動するように設定します

自動起動のON
 # chkconfig denyhosts on
 自動起動の設定を確認
 # chkconfig --list denyhosts
 denyhosts 0:off 1:off 2:on 3:on 4:on 5:on 6:off
 DenyHosts を起動
 # /etc/init.d/denyhosts start
 Starting denyhosts: [ OK ]

スポンサーリンク

0
0

LinuxCentOS 6,denyhosts,Linux,ssh

Posted by admin