A simple PAM module written in Go that counts failed login attempts and takes action once a defined threshold is reached.
By default, the module shuts down the system (systemctl poweroff) when too many incorrect login attempts are detected.
- Counts failed login attempts per user.
- Securely stores the counter in
/var/lib/pam_wrongpass. - Resets the counter on successful login.
- Shuts down the system when the number of failed attempts reaches
max_tries. max_triescan be configured directly in the PAM configuration.
Go to Releases and download the .so file for your architecture:
pam_wrongpass_linux_amd64.so– 64-bit x86 (most desktops and servers)pam_wrongpass_linux_arm64.so– 64-bit ARM (e.g., Raspberry Pi)
Copy the file to the PAM modules directory:
sudo install -m 0644 pam_wrongpass_linux_amd64.so /usr/lib/security/pam_wrongpass.soNote: Some distributions use
/lib/security/instead of/usr/lib/security/.
The module stores counters securely in /var/lib/pam_wrongpass.
Make sure the directory exists and has the correct permissions:
sudo mkdir -p /var/lib/pam_wrongpass
sudo chmod 700 /var/lib/pam_wrongpass
sudo chown root:root /var/lib/pam_wrongpassEdit your system's PAM configuration files for login.
On most systems, these are common-auth and common-account under /etc/pam.d/.
Add at the top of /etc/pam.d/common-auth:
auth optional pam_wrongpass.so max_tries=5
Add at the top of /etc/pam.d/common-account:
account required pam_wrongpass.so
max_tries=5means the system will shut down after 5 failed login attempts.- If omitted, the default value is
10.
You can test using pamtester:
sudo pamtester login <your_username> authenticateEnter incorrect passwords repeatedly.
When the threshold is reached, the system will start shutting down via systemctl poweroff.
On Debian/Ubuntu:
sudo apt-get update
sudo apt-get install -y build-essential libpam0g-dev golanggo build -buildmode=c-shared -o pam_wrongpass.so pam_wrongpass.goCopy the built file into the PAM directory:
sudo install -m 0644 pam_wrongpass.so /usr/lib/security/pam_wrongpass.so| Parameter | Description | Default |
|---|---|---|
max_tries |
Number of failed login attempts before shutdown | 10 |
Example configuration with shutdown after 3 failed attempts:
auth optional pam_wrongpass.so max_tries=3
- Counters are stored securely in
/var/lib/pam_wrongpasswithroot:rootownership and0700permissions to prevent tampering. - Users cannot reset or modify the counter themselves.
- If you want to lock the system instead of shutting it down, replace the
systemctl poweroffcommand in the source code with another action, such as disabling the user account.
-
Check PAM logs:
sudo journalctl -xe | grep pam_wrongpass -
Ensure the
.sofile is in the correct PAM directory:/usr/lib/security/or/lib/security/depending on your distribution.
-
Verify that
libpam0g-devis installed if building from source.
If you need to iterate during development, you can run the build workflow manually using:
make buildOr trigger the GitHub Action using:
gh workflow run "Build PAM Wrongpass Module"Use at your own risk. Misconfiguring a PAM module can lock you out of your system. Always test in a safe environment (such as a virtual machine) before deploying on production systems.
This project is released under the MIT License.