How to lock out a user to login a system after a set number of failed attempts?

 11시 09분 2014년 5월 2일 업데이트

문제

  • How to lock out a user to login a system after a set number of failed attempts?

환경

  • Red Hat Enterprise Linux 4
  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6

해결

Pluggable Authentication Module (PAM) comes with the pam_tally login counter module. pam_tally has the capability to maintain attempted access count, reset counters on successfull logins and also lock out users with multiple failed login attempts.

In the authentication phase of /etc/pam.d/system-auth and /etc/pam.d/password-auth files the pam_tally deny parameter can be used to restrict the number of failed login attempts. The user account will be locked out once the login attempts exceed the deny tally value.

The examples shown below are configured to allow a maximum number of 3 failed login attempts before it locks the user's account.

With Red Hat Enterprise Linux 3, 4 pam_tally, add two entries need to be added in the same file:

auth     required        /lib/security/$ISA/pam_tally.so onerr=fail
account  required        /lib/security/$ISA/pam_tally.so deny=3

See below for a complete example of implementing this type of policy:

# cat /etc/pam.d/system-auth
auth     required        /lib/security/$ISA/pam_env.so
auth     required        /lib/security/$ISA/pam_tally.so onerr=fail
auth     sufficient      /lib/security/$ISA/pam_unix.so likeauth nullok
auth     required        /lib/security/$ISA/pam_deny.so

account  required        /lib/security/$ISA/pam_unix.so
account  required        /lib/security/$ISA/pam_tally.so deny=3 reset
.... snip .....

The options used above are described below:

  • onerr=fail : If something strange happens, such as unable to open the file, this determines how the module should react.
  • deny=3 : The deny=3 option is used to deny access if tally for this user exceeds 3.
  • reset : This option resets failed count to 0 on successful entry

For more information refer to /usr/share/doc/pam-<version>/txts/README.pam_tally

With Red Hat Enterprise Linux 5 pam_tally, add the following lines about pam_tally.so in the default files /etc/pam.d/system-auth and /etc/pam.d/password-auth:

auth     required      pam_tally.so onerr=fail deny=3
account  required      pam_tally.so

And the /etc/pam.d/system-auth will be changed as following:

auth     required      pam_env.so
auth     required      pam_tally.so onerr=fail deny=3
auth     sufficient    pam_unix.so nullok try_first_pass
auth     requisite     pam_succeed_if.so uid >= 500 quiet
auth     required      pam_deny.so

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

Note : The reset option is not necessary in the Red Hat Enterprise Linux 5. For more information, refer its manual page running the command "man pam_tally".

With Red Hat Enterprise Linux 6, pam_tally has been renamed to pam_tally2 so these would be the lines to be added to /etc/pam.d/system-auth and /etc/pam.d/password-auth files:

auth     required      pam_tally2.so onerr=fail deny=3
account  required      pam_tally2.so

And a /etc/pam.d/system-auth file would look like this:

auth     required      pam_env.so
auth     required      pam_tally2.so onerr=fail deny=3
auth     sufficient    pam_unix.so nullok try_first_pass
auth     requisite     pam_succeed_if.so uid >= 500 quiet
auth     required      pam_deny.so

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

The attempts will be logged in /var/log/faillog file. faillog command reports on the number of failed login attempts for a specific user.

# faillog -u <username>

To manually unlock a locked user account, execute the following command:

# faillog -u <username> -r

For advanced usages:

NOTE



+ Recent posts