Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Contact
  • Reviews
  • Toggle search form
Home » Linux » How to Configure Advanced PAM in Linux
  • image 22
    How to clone a Windows Server running on VirtualBox Virtualization
  • Entire VM restore
    Restore VM to Original location using Veeam Entire VM restore Backup
  • Wyebot
    A comprehensive guide on Wyebot Wireless Intelligence Platform Reviews
  • Feature image
    How to search Group Policy for a specific Setting in Windows 10 and 11 Windows
  • Certificate does not contain the private key
    Server Certificate could not be updated: Private key does not match Windows Server
  • fast user switching in windows 10 1
    Fast user switching: How to create a desktop shortcut in Windows 10 to switch User Accounts Windows
  • uninstalloffice
    Remove All Microsoft Office Apps from Mac Network | Monitoring
  • vmwarevinchin
    3 Ways to Convert VMware VMs to Hyper-V Backup

How to Configure Advanced PAM in Linux

Posted on 22/12/202125/03/2024 Raphael Gab-Momoh By Raphael Gab-Momoh No Comments on How to Configure Advanced PAM in Linux
feature_image

The Pluggable Authentication Module (PAM) adds a layer of security to administrative tools and commands. It includes dynamically loadable libraries that dictate how different applications verify and authenticate users. Explore this article to learn how to configure advanced PAM in Linux. In this article, we shall learn how to Configure Advanced PAM in Linux. Please see Unable to bind to LDAP or AD in Pleasant Password Server, and What’s New? Install Windows Server 2025 and enable RDP.

You can find other related guides here: Delivering System Utilization Report on a Linux based OS, and how to enable LDAP over SSL with a third-party Certificate such as DigiCert.

Understanding Advanced PAM

You have used advanced PAM if you are logged on to a Linux system without realizing, SSH also uses PAM. It is also used to make user authentication standard. The config files can be located in /etc/pam.d/login

auth [ user Unkown=ignore success=ok ignore=ignore default=bad] pam_securetty.so

The highlight text is a syntax of a pam rule, the rule type is auth. What the rule does is to make sure pam_securetty.so ensures that the root user is logging in.

And if it is, it makes sure that the user is logged in from a secured terminal, which is /etc/securetty.

So, everyone that is trying to login as root and not from a secured terminal will have their access denied . A user can only login from a secured terminal defined in /etc/securetty. Configuration files are named according to the programs using them in /etc/pam.d/

TYPES OF PAM RULES:
Authentication Management (Auth) this validates a user's identity
Account Management and this will allow or deny based on access policy
Password management, manages password change policies
Session management, applies settings for user sessions

TYPES OF PAM  CONTROL FLAGS:

Required if the first rule passes PAM proceeds to the next rule of the same type, if it fails PAM still proceeds but the result returns a failure
Requisite If this passes, PAM does not check any more rules 
Sufficient If this rule passes, no other rule of the same type gets processed
Optional Whether it passes or fails, PAM continues to the next
Include Includes all rule of the same type from designated configuration files

Demo

#cd /etc/pam.d
#ls

Configuring Advanced PAM in Linux

When we get into this config directory, we will realize that there are lots of files there, normal and some symbolic links, the symbolic links all reference parent, for example passwd-auth is a symbolic link to passwd as shown in the screenshot below.

If we cat for samba in the screenshot below. We will see that all the rule types mentioned above are accounted for.

pamdjpg
/etc/pam.d files
cat samba
how to configure PAM in Linux-ruletype-1
rule types
control-flags
control flags

We should notice the rule types are in red and the control flags are in blue. If we further cat into any of the files in the required flag. We can see that the files are further separated into the required rule types; auth, account, password, and session.

how to configure PAM in Linux-auth-1
cat password-auth

Understand Control Flags

As we can see, each of the flag is strictly adhered to, The rules are processed in order as the control flags imply.

Looking at the screenshot carefully, we can see that it is required that the environment is set up first and next it is required to set a delay on failure.

The next two steps showed that the process was successful, next it is sufficient to not require any other form of restriction.

Again, it is sufficient that if the first password passes, we can login without any issues. The last one determines what happens to the error generated in the log file when a failure finally happens.

If we cat sshd we will see that it is also separated into sections s and there quite a few number of include lines, to see what those do, we have to cat to see what’s in, lets cat into postlogin for example

how to configure PAM in Linux-include
cat sshd
does-nothing
no password-auth

Modify PAM Configuration

The postlogin server example does not do anything because we do not have an auth rule type to include, if we look at the screenshot above carefully, account and password do include password-auth. So, let’s cat into password-auth

how to configure PAM in Linux password-auth

So, if we cat into account or password rule type as shown above. We get these results shown

how to configure PAM in Linux-accountpassword
account & password

As we can see, we do have things in account and password rule type that need to be pulled in and processed.

Ideally, the tool to use to update these files is called authconfig-tui so if you are going to amend these files, the best practice for manipulating things with an n-cursor interface is to use the tool.

 #authconfig-tui
how to configure PAM in Linux-authconfig
authconfig-tui

We can scroll through and configure any of the parameters using this tool instead of manually changing anything.

To select an item, you need to hit the space bar on your keyboard. So, assuming we have ldap installed on the system and we select ldap, we just hit space to select ldap and click on next.

how to configure PAM in Linux-ldap
settings without ldap configured

We tried to set up ldap and it returned the message in the screenshot. So let’s set up ldap to configure advanced PAM.

how to configure PAM in Linux-dcng
ldap settings

It had blank values, so we use ldap.example.com as the server and base DN as dc=ng, dc=local, to see if what we did succeeded in adding ldap to the files. Lets run the command

#grep ldap *
how to configure PAM in Linux-pamldap
pam_ldap
From the image above, we see that pam_ldap has been added to the files. 

We need to make a change to the default login definitions and change UID to 500

#vim /etc/login.defs
uid
uid_min

Update

Next thing to do to configure advanced PAM in Linux is to make the change reflect in all the files. So use the code below

#authconfig --updateall
authconfig-1

By default, PAM authentication is set to succeed if UID is greater than 1000 but we have set it to 500, so if we do a grep 500 * , we will see that everything has been changed to 500.

500
PAM _succeed if uid >=500

Install PAM Modules

There are lots of modules preconfigured in the system that we can add to PAM and we can find these in

# ll /usr/lib64/security/pam*
pam-tall
pre-configured modules

One of such module that is usually used very often is PAM_tally. And we can check this from the man pages as well. we can get more information about tally2 module

#man pam_tally2
pam-tally2
man_tally2

Man pam tally2 gives an interesting example. with the code line highlighted in the screenshot

#vim /etc/pam.d/login
# pam_tally2.s0 deny=4  even deny root unlock time = 2000

The line of the second code we copied from the tally2 man page will lock the account after 4 failed login attempt and it will even lock root, after 20 minutes it will unlock the account.

If we paste the code in the auth stack of vim/etc/pam.d/login, pam_tally2 will be called anytime we fail to login

Summary

By now, you should have a clear understanding of how to configure advanced PAM in Linux.

Bear in mind that Pam uses control flags and rules to implement security of how users are authenticated. It is not advisable to configure it manually.

We use authconfig-tui to configure LDAP and other necessary settings. We can add a popular module called pam_tally2 to our auth stack to checkmate how our system should act when a user fails to login.

Rate this post

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Pocket (Opens in new window) Pocket
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • Share on Nextdoor (Opens in new window) Nextdoor
Linux Tags:LDAP

Post navigation

Previous Post: Stuck at Start PXE over IPv4: PXE-E18 Server response timeout
Next Post: How to Install LAMP Stack on Ubuntu 18.04

Related Posts

  • How to use Netstat.exe to confirm which Program uses or blocks a port
    How to use Netstat.exe to confirm which Program uses or blocks a port Linux
  • 517443 637286201540125528 16x9 1
    User account and process management in Linux Linux
  • Security enhanced linux
    How to setup SELinux on a Linux server Linux
  • Screenshot 2021 02 05 at 22.40.51
    Disable automatic screen lock on Ubuntu Desktop Linux
  • SSL on WAMPServer
    Setup VirtualHost with SSL on WAMP Server Linux
  • lampstack feature lamp stack ubuntu
    How to Install LAMP Stack on Ubuntu 18.04 Linux

More Related Articles

How to use Netstat.exe to confirm which Program uses or blocks a port How to use Netstat.exe to confirm which Program uses or blocks a port Linux
517443 637286201540125528 16x9 1 User account and process management in Linux Linux
Security enhanced linux How to setup SELinux on a Linux server Linux
Screenshot 2021 02 05 at 22.40.51 Disable automatic screen lock on Ubuntu Desktop Linux
SSL on WAMPServer Setup VirtualHost with SSL on WAMP Server Linux
lampstack feature lamp stack ubuntu How to Install LAMP Stack on Ubuntu 18.04 Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a

  • image 22
    How to clone a Windows Server running on VirtualBox Virtualization
  • Entire VM restore
    Restore VM to Original location using Veeam Entire VM restore Backup
  • Wyebot
    A comprehensive guide on Wyebot Wireless Intelligence Platform Reviews
  • Feature image
    How to search Group Policy for a specific Setting in Windows 10 and 11 Windows
  • Certificate does not contain the private key
    Server Certificate could not be updated: Private key does not match Windows Server
  • fast user switching in windows 10 1
    Fast user switching: How to create a desktop shortcut in Windows 10 to switch User Accounts Windows
  • uninstalloffice
    Remove All Microsoft Office Apps from Mac Network | Monitoring
  • vmwarevinchin
    3 Ways to Convert VMware VMs to Hyper-V Backup

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,832 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.