What is pam_faillock and how to use it in Red Hat Enterprise Linux ?

环境

  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • PAM
  • pam_faillock.so

问题

  • What is pam_faillock ? How to implement account lockout policy using pam_faillock.so ?
  • pam_tally is deprecated in RHEL6, what can I configure instead of pam_tally ?
  • How do I reset/view failure attempts of user for pam_faillock ?
  • How can I use pam_faillock to disable a particular user(s) from getting locked out after multiple unsuccessful login attempts?
  • Since faillog command (pam_tally) is not available in RHEL 6.1, how do I use pam_faillock instead ?
  • Steps to configure faillock in RHEL 6.1
  • pam_tally counter reset does not work correctly

决议

Configure /etc/pam.d/system-auth and /etc/pam.d/password-auth as below:

Case 1:

Raw

auth        required      pam_env.so
auth        required      pam_faillock.so preauth silent audit deny=3 unlock_time=600
auth        sufficient    pam_unix.so nullok try_first_pass
auth        [default=die] pam_faillock.so authfail audit deny=3 unlock_time=600
auth        requisite     pam_succeed_if.so uid >= 500 quiet
auth        required      pam_deny.so

account     required      pam_faillock.so
account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 500 quiet
account     required      pam_permit.so

..snip..

Case 2:

Raw

auth        required      pam_env.so
auth        [success=1 default=ignore] pam_unix.so nullok try_first_pass
auth        [default=die] pam_faillock.so authfail audit deny=3 unlock_time=600
auth        sufficient    pam_faillock.so authsucc audit deny=3 unlock_time=600
auth        requisite     pam_succeed_if.so uid >= 500 quiet
auth        required      pam_deny.so

account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 500 quiet
account     required      pam_permit.so

..snip..

The above configuration file would lock out users after 3 unsuccessful login attempts and unlock them after 10 minutes.

  • To lock out root user, auth required pam_faillock.so line should be added in both /etc/pam.d/system-auth and /etc/pam.d/password-authas follows :

Raw

auth    required    pam_faillock.so preauth silent audit deny=3 even_deny_root unlock_time=1200 root_unlock_time=600
  • To disable a user from locking out even after multiple failed logins add the below line just above the pam_faillock in both /etc/pam.d/system-auth and /etc/pam.d/password-auth and replace user1, user2 with the actual usernames.

Raw

auth [success=1 default=ignore] pam_succeed_if.so user in user1:user2:user3

For more information of parameters in pam_faillock.so refer man page of pam_faillock.

  • To reset/view authentication failure records use commands given below:
    For displaying authentication failure records:

Raw

# faillock --user <username>

And for resetting authentication failure records:

Raw

# faillock --user <username> --reset

SSHD configuration adjustment

  • If pam_faillock.so is not working as expected, the following changes may have to be made to SSHD's configuration:

Raw

# vi /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
PasswordAuthentication no

Then restart the sshd service in order for these configuration changes to take effect:

Raw

# systemctl restart sshd
  • Note: Sequence of the lines in the files are important and any change in sequence would end up locking all users including root user when you are using even_deny_root option.

  • References:
    Where is faillog command for Red Hat Enterprise Linux 6 ?

  • Note: pam_faillock module support temporary locking of user accounts in the event of multiple failed
    authentication attempts. This new module improves functionality over the existing pam_tally2 module, as it also
    allows temporary locking when the authentication attempts are done over a screensaver.

  • Note: pam_faillock now also support persistent locking via errata release RHBA-2016-2314.

 

转载至https://access.redhat.com/solutions/62949

在 CentOS 8 离线环境下安装 `pam_faillock.so` 需要通过手动下载依赖包并复制到系统中的相应位置。首先,你需要确定这个模块属于哪个软件包,通常它来自于 `pam-modules` 或 `pam-generic` 包。 **步骤如下:** 1. **下载文件:** - 访问 http://ftp.rpmfind.net/linux/fedora/releases/$(rpm -E %fedora)/pub/pam/ (替换 $(rpm -E %fedora) 为你当前的Fedora版本),然后找到包含 `pam_faillock.so` 的 `.tar.gz` 文件。 - 将文件下载到本地某个目录,例如 `/root/download`。 2. **解压文件:** ``` cd /root/download tar xvfz pam-faillock*.tar.gz ``` 3. **查找`pam_faillock.so`的位置:** 找到解压后的目录,通常在 `usr/lib64/security` 或 `usr/lib/security` 下,根据你的系统架构选择正确的目录。 4. **复制文件:** ``` sudo cp /path/to/pam_faillock.so /usr/lib64/security/ (对于64位系统) or sudo cp /path/to/pam_faillock.so /usr/lib/security/ (对于32位系统) ``` 5. **加载模块:** 使用 `pam` 工具加载新的模块,如果成功会显示该模块已被加载: ``` sudo pammodules-load pam_faillock.so ``` 6. **更新配置:** 可能需要更新系统服务的 PAM 配置文件,如 `/etc/pam.d/common-password`、`/etc/pam.d/su` 等,确保包含了对 `pam_faillock.so` 的引用。 7. **重启服务:** 为了使更改生效,可能需要重启需要使用此模块的服务,比如 `systemctl restart sshd` 或 `systemctl restart passwd-auth`. **注意事项:** - 这种方法仅适用于 CentOS 8 系统的本地环境,如果你连接网络,建议直接使用 `yum` 或 `dnf` 安装。 - 如果你的系统管理员认为这样做不合适,你应该遵循他们的指导来进行安装。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值