Linux Tricks and Techniques

For Linux Experts

Use the website for easy leaning of Linux

Friday, 8 July 2016

Reset pam_tally2 Authentication in Linux

How to reset locked account of a user due to wrong passwords using pam_tally2

pam_tally2 module is used to lock user accounts after certain number of failed ssh login attempts made to the system. This module keeps the count of attempted accesses and too many failed attempts.

pam_tally2 module comes in two parts, one is and another is pam_tally2. It is based on PAM module and can be used to examine and manipulate the counter file. It can display user login attempts counts, set counts on individual basis, unlock all user counts.

Lock SSH Logins
Pam_tally2 to Lock SSH Logins
By default, pam_tally2 module is already installed on the most of the Linux distributions and it is controlled by PAM package itself. This article demonstrates on how to lock and unlock SSH accounts after reaching a certain failed number of login attempts.

How to Lock and Unlock User Accounts
Use ‘/etc/pam.d/password-auth‘ configuration file to configure login attempts accesses. Open this file and add the following AUTH configuration line to it at beginning of the ‘auth‘ section.

auth        required  file=/var/log/tallylog deny=3 even_deny_root unlock_time=1200

Next, add the following line to ‘account‘ section.

account     required

file=/var/log/tallylog – Default log file is used to keep login counts.
deny=3 – Deny access after 3 attempts and lock down user.
even_deny_root – Policy is also apply to root user.
unlock_time=1200 – Account will be locked till 20 Min. (remove this parameters if you want to lock down permanently till manually unlock.)
Once you’ve done with above configuration, now try to attempt 3 failed login attempts to server using any ‘username‘. After you made more than 3 attempts you will get the following message.

[root@khatri ~]# ssh khatri@
khatri@'s password:
Permission denied, please try again.
khatri@'s password:
Permission denied, please try again.
khatri@'s password:
Account locked due to 4 failed logins
Account locked due to 5 failed logins
Last login: Mon Apr 22 21:21:06 2013 from
Now, verify or check the counter that user attempts with the following command.

[root@khatri ~]# pam_tally2 --user=khatri
Login           Failures  Latest    failure     From
khatri          5    04/22/13  21:22:37
How to reset or unlock the user account to enable access again.

[root@khatri pam.d]# pam_tally2 --user=khatri --reset
Login           Failures  Latest    failure     From
khatri           5     04/22/13  17:10:42
Verify login attempt is reset or unlocked

[root@khatri pam.d]# pam_tally2 --user=khatri
Login           Failures   Latest   failure     From
khatri          0
The PAM module is part of all Linux distribution and configuration provided about should work on all Linux distribution. Do ‘man pam_tally2‘ from the command line to know more about it.


No comments:
Write comments