Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
Linux ›
Linux password lockout policy

Linux password lockout policy

May 7, 2011 Linux Jesin A Leave a Comment

linux password lockout policy thumbnail

Linux password lockout policy can be configured using PAM (Pluggable Authentication Modules) to lock a user’s account temporarily if they attempt to bruteforce into an account by trying various password combinations. This configuration uses the pam_tally2.so module. Bruteforce hacking is a method to find a user’s password by trying to login with various password combinations. By having a password lockout policy such users can be locked out of their account if a certain number of incorrect passwords are entered. While trying this tutorial in your system make sure you have the file /lib/security/pam_tally2.so if it isn’t there trying this out will lock all user accounts even if you enter the correct password.

Using a text editor open the following file

nano /etc/pam.d/system-auth

add the following text to the second line.

auth required pam_tally2.so deny=3 unlock_time=3600

The above statement will lock an user account if incorrect passwords are entered three or more times as specified in the deny option. The account will be unlocked after 3600 seconds as specified in the unlock_time option. Choose the number of incorrect attempts and unlock time wisely. There is also another option which will enforce this policy for the root user.

auth required pam_tally2.so deny=3 unlock_time=3600 even_deny_root

The even_deny_root will lockout the root user also. So use this option with caution. After this is done add another line in the account section in the same file

account required pam_tally2.so

Save the /etc/pam.d/system-auth file, before testing your configuration open another terminal and try to login as any user with a CORRECT password, if you’re unable to login at this stage there is something wrong with the /etc/pam.d/system-auth file. If you’re able to login successfully try by logging in using the correct username and wrong password. Each time you try execute the following command as root to find the number of authentication failure attempts.

pam_tally2

or

pam_tally2 -u username

to see information regarding a specific user (Replace username with the actual user).

If you enter the incorrect password for certain number of times the following message will appear as soon as the username is entered

Account locked due to 4 failed login attempts

To manually unlock the account before the unlock_time use the following command

pam_tally2 -u username -r

A more conservative usage of the above command is to deduct the number of times the user has logged in unsuccessfully. For example, if the password retries is 3 and user Alice has tried logging in with an incorrect password 4 times, using the above command to unlock the account will give another 3 tries for the username Alice which might give more attempts for a potential hacker. Instead the incorrect attempts counter value can be set to 2 so that Alice has just one more attempt.

pam_tally2 -u username --reset=2

will set the incorrect password counter for the user to 2.

In case the root user is locked out and you immediately need to login as root, boot your system into single user mode and execute the following command.

pam_tally2 -u root -r

For instructions read the article Reset Root Password in Linux

Related posts:

networking category thumbnailCisco Account Lockout using login block-for linux category thumbnailForgot MySQL root user password (Linux) linux category thumbnailReset Root Password in Linux linux category thumbnailLinux ACL Tutorial change default runlevel in linuxHow to change the default runlevel in Linux

Tags: account lockout, linux, linux system files

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.