Debian 系 OS でログインを一定回数失敗したアカウントをロックする
設定手順
-
cd /etc/pam.d/ -
sudo cp common-auth common-auth.bk -
sudo vim common-auth
#
# /etc/pam.d/common-auth - authentication settings common to all services
#
# This file is included from other service-specific PAM config files,
# and should contain a list of the authentication modules that define
# the central authentication scheme for use on the system
# (e.g., /etc/shadow, LDAP, Kerberos, etc.). The default is to use the
# traditional Unix authentication mechanisms.
#
# As of pam 1.0.1-6, this file is managed by pam-auth-update by default.
# To take advantage of this, it is recommended that you configure any
# local modules either before or after the default block, and use
# pam-auth-update to manage selection of other modules. See
# pam-auth-update(8) for details.
# deny=N で N 回失敗でロックされる. (root は適用外)
# root にも適用する明愛には [even_deny_root] を追加する.
# unlick_time=N で N 秒経過すると自動的にロックが解除される
# (自動ロック解除しない場合には unlock_time を指定しない)
# even_deny_root で root も適用した場合には root_unlock_time=N で自動ロック解除時間を指定できる.
# 1 週間後に自動ロックを解除するため 60 * 60 * 24 * 7 = 604800 sec を指定する.
auth required pam_tally2.so deny=5 unlock_time=604800 even_deny_root root_unlock_time=604800
# here are the per-package modules (the "Primary" block)
auth [success=1 default=ignore] pam_unix.so nullok_secure
# here's the fallback if no module succeeds
auth requisite pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
auth required pam_permit.so
# and here are more per-package modules (the "Additional" block)
# end of pam-auth-update config
-
sudo cp common-account common-account.bk -
sudo vim common-account
#
# /etc/pam.d/common-account - authorization settings common to all services
#
# This file is included from other service-specific PAM config files,
# and should contain a list of the authorization modules that define
# the central access policy for use on the system. The default is to
# only deny service to users whose accounts are expired in /etc/shadow.
#
# As of pam 1.0.1-6, this file is managed by pam-auth-update by default.
# To take advantage of this, it is recommended that you configure any
# local modules either before or after the default block, and use
# pam-auth-update to manage selection of other modules. See
# pam-auth-update(8) for details.
#
# 追記
account required pam_tally2.so
# here are the per-package modules (the "Primary" block)
account [success=1 new_authtok_reqd=done default=ignore] pam_unix.so
# here's the fallback if no module succeeds
account requisite pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
account required pam_permit.so
# and here are more per-package modules (the "Additional" block)
# end of pam-auth-update config
-
cd /etc/ssh/ -
sudo vim sshd_config-
UsePAM yesとなっていることを確認する. (デフォルトではyesに設定されている.)
-
-
sudo systemctl restart sshd.service
アカウントロックの確認とロック解除
-
ssh ユーザー名@アドレスで複数回誤ったパスワードでログインを試し、アカウントがロックされることを確認する.-
アカウントがロックされると正しいパスワードを入れても
Permission denied, please try again.と表示されるようになる.
-
-
アカウントロックを解除するためには以下のコマンドを実行すればよい.
-
ssh でアカウントロックがされていても、vnc でのパスワードログインは問題なく行えた.
-
# ログイン失敗確認
$ sudo /usr/sbin/pam_tally2 -u ユーザ名
Login Failures Latest failure From
ユーザ名 12 05/21/23 19:03:23 192.168.0.16
# アカウントロック解除
$ sudo /usr/sbin/pam_tally2 -r -u ユーザ名
Login Failures Latest failure From
ユーザ名 12 05/21/23 19:03:23 192.168.0.16