Rate this page del.icio.us  Digg slashdot StumbleUpon

How do I use the faillog program to track failed login attempts?

by

Faillog is a small Linux utility that reports on the number of failed login attempts for a specific user. This utility requires modifying pam settings to work. Below are the steps to set up the faillog utility:

  1. Open the /etc/pam.d/system-auth file for editing.
  2. Add the following lines:
    auth      required     pam_tally.so no_magic_root
    account   required     pam_tally.so deny=2 no_magic_root
    
  3. Save the file and exit.
  4. Test the configuration by attempting to login as a normal user, but using a wrong password.
  5. Verify the failed count increments by running the command:
    faillog -u 
    

contributed by Jeremy West

Red Hat’s customer service and support teams receive technical support questions from users all over the world. Red Hat technicians add the questions and answers to Red Hat Knowledgebase on a daily basis. Access to Red Hat Knowledgebase is free. Every month, Red Hat Magazine offers a preview into the Red Hat Knowledgebase by highlighting some of the most recent entries.

6 responses to “How do I use the faillog program to track failed login attempts?”

  1. Stephen Smoogen says:

    This can cause a problem on RHEL-4 with xlock, xscreensaver, and other non-root level tools. The reason is that only root has access to the /var/log/faillog file.. so that xscreensaver cannot write to it when you try to unlock your screen.

    The solution is to customize your non-root-level pam files from the system-auth ones. I tend to have 2 files:

    /etc/pam.d/system-auth-root
    /etc/pam.d/system-auth-nonroot

    then I do a

    sed -ie ‘s/system-auth$/system-auth-nonroot/’ /etc/pam.d/kscreensaver

    I then copy the system-auth-root to /etc/pam.d/system-auth (this makes sure that I have a valid copy in the case that authconfig is run and the /etc/pam.d/system-auth is overwritten.)

    or similar change command. This allows faillog to only be tried on things that faillog can write to.

    In areas that you need to have a written security policy, the reasoning to use for such an exception is that a person who has console access to the system has enough physical access to bypass a faillog lockout, or you use a script to log xscreensaver etc attempts seperately.

  2. Chris Patterson says:

    system-auth works unless you use ssh exclusively for access to a system. You then need to modify the sshd file under pam. I have found that if both files are modified you get double the login failures. I have telnet disabled so I only modify sshd.

    auth required pam_tally.so onerr=fail no_magic_root
    account required pam_tally.so deny=3 no_magic_root reset per_user

    The plus side to using sshd is that authconfig does not overwrite your modifications.

  3. Martin says:

    I use RedHat EL4, and the first few lines of the file are:
    #%PAM-1.0
    # This file is auto-generated.
    # User changes will be destroyed the next time authconfig is run.

    So that would mean that the changes are not permanent, or did I get this wrong?

  4. Ram says:

    Martin: Only if you use the authconfig tool (it’s under System Settings|Authentication in the GUI). We remove authconfig in our environment to make sure that doesn’t happen

  5. Jim Clarke says:

    Re: How do I use the faillog program to track failed login attempts?
    I have entered the lines as suggested in my /etc/pam.d/system-auth file but, it doesn’t seem to work. When I check the faillog file it will show 4 failures, max 0. I then changed the max to 2 (faillog -m2), reset my (faillog -r), which reset my failures. Then tried again and now I get failures 4, max 2. But then I can still log in as that user without unloacking the accounr. Any help would be greatly appreciated.

  6. Eric Reischer says:

    This is another example of Red Hat trying to do things the Microsoft way and making life miserable for sysadmins. If everyone is so worried about “authconfig” overwriting the changes in configuration files, why doesn’t someone write the authconfig tool the right way, and instead of having it blindly overwriting the files in /etc/pam.d, have it read in the configuration from the /etc/pam.d files and present those as the default to the user when they call the tool. That way any changes will be preserved. This is unfortunately the way RedHat handles the vast majority of their config files, and I strongly disagree with the policy.