SSHのIP制限

SSHでのログインに対してIPアドレスでの制限をかけます。
「/etc/hosts.allow」で許可するIPアドレス(ドメイン名)を記載して、「/etc/hosts.deny」で拒否するIPアドレス(ドメイン名)を記載します。

まず、「/etc/hosts.allow」を編集します。
# vi /etc/hosts.allow
(例)
#
# hosts.allow   This file describes the names of the hosts which are
#               allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
sshd: ***.***.***.***
※複数のIPアドレスを記載できます。(書式に関してはマニュアル等を参照して下さい。)

次に、「/etc/hosts.deny」を編集します。
# vi /etc/hosts.deny
 

全てのアクセスを拒否します。
#
# hosts.deny    This file describes the names of the hosts which are
#               *not* allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow.  In particular
# you should know that NFS uses portmap!
sshd: All

「hosts.allow」、「hosts.deny」は保存すると直ぐに反映されます。
ファイルの編集の順序や記述内容を間違ってしまうと、最悪の場合次回からサーバへのログインができなくなってしまう場合があるので、十分注意して下さい。



最終更新:2021年12月13日 10:38