- 検証環境
- CentOS Linux release 7.8
sshdはデフォルトでPAM認証を利用する。UsePAM
のパラメータがyes
になっている。
/etc/ssh/sshd_config
UsePAM yes
/etc/pam.d/password-auth
を編集する。
/etc/pam.d/password-auth
[変更前]
auth required pam_env.so
auth sufficient pam_unix.so try_first_pass nullok
auth required pam_deny.so
[変更後]
# %PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth required pam_env.so
# Add setting
auth required pam_faillock.so preauth silent audit deny=3 unlock_time=3600
auth sufficient pam_unix.so try_first_pass nullok
# Add setting
auth [default=die] pam_faillock.so authfail audit deny=3 unlock_time=3600
auth required pam_deny.so
account required pam_unix.so
# Add setting
account required pam_faillock.so
記載順によって評価が変化するため注意する。
auth
ユーザ認証を行う。
account
ユーザ認証が可能か確認する。
required
モジュールの実行に失敗してもすぐに拒否せず、同じタイプのモジュールの実行が全て失敗した時点で認証を拒否する。
sufficient
モジュールの実行に成功した場合、より上位のrequired行が全て成功であれば、その時点で認証を成功とする。失敗した場合は引き続き評価する。
faillock
コマンドで認証失敗情報を表示する。3回認証失敗した場合は、以下のように表示される。
[root@c ~]# faillock
u1:
When Type Source Valid
2021-01-05 21:22:07 RHOST m014011003224.v4.enabler.ne.jp V
2021-01-05 21:22:10 RHOST m014011003224.v4.enabler.ne.jp V
2021-01-05 21:22:13 RHOST m014011003224.v4.enabler.ne.jp V
アカウントロックされると、アンロック時間を超えるまで正しいパスワードを入力してもログインできなくなる。
> ssh u1@c.example.com
u1@c.example.com's password:
u1@c.example.com's password:
u1@c.example.com's password:
Permission denied (publickey,password).
手動でリセットすることもできる。
[root@c ~]# faillock --user u1 --reset
PAMの詳しい使用方法が知りたければ、The Linux-PAM System Administrators' Guide を見てみる。
The Linux-PAM System Administrators' Guide
http://www.linux-pam.org/Linux-PAM-html/Linux-PAM_SAG.html