PAM (Pluggable Authentication module) Usage and Configuration in Linux : All about PAM to know.

1. PAM Introduction

Pluggable authentication module (PAM) provides a mechanism to incorporate multiple low-level authentication schemes into a high-level application programming interface (API).

Sun Microsystems introduced the concept of PAM in an Open Software Foundation RFC(Request for Comments) 86.0 dated October 1995.

Linux Pluggable Authentication Modules provides a feature to put various checks w.r.t authentication and user account validation.

PAM provides dynamic authentication & validation of user account support to provide secure access of applications and services in a Linux.

2. Various PAM Modules in Linux

In Linux, we have different PAM modules available. The most widely used and developed modules include the following:

a. Account modules :- Whether account is valid or not.
b. Authentication modules :- Verify user password and other identities.
c. Password modules :- Provides feature to updating password.
d. Session modules :- Actions to be performed at beginning or end of the session.

3. PAM Configuration in Linux

PAM configuration either resides in /etc/pam.conf or in /etc/pam.d/ directory.
If /etc/pam.d directory exists, then /etc/pam.conf file is ignored.

[root@nglinux ~]# ls /etc/pam.d/
abrt-cli-root        gdm               reboot             sudo
amdcccle-su          gdm-autologin     remote             sudo-i
atd                  gdm-password      run_init           system-auth
authconfig           halt              runuser            system-auth-ac
authconfig-gtk       liveinst          runuser-l          system-config-authentication
authconfig-tui       login             setup              system-config-date
chfn                 newrole           smartcard-auth     system-config-keyboard
chsh                 other             smartcard-auth-ac  system-config-language
config-util          passwd            smtp               system-config-network
crond                password-auth     smtp.postfix       system-config-network-cmd
cups                 password-auth-ac  ssh-keycat         system-config-users
eject                polkit-1          sshd               vmtoolsd
fingerprint-auth     poweroff          su                 vsftpd
fingerprint-auth-ac  ppp               su-l               xserver
[root@nglinux ~]# 

4. PAM log file

Usually PAM logs are saved in /var/log/secure file. However we advise to look for “pam” keyword in all logs.

secure:Oct  1 18:54:50 localhost sshd[1849]: pam_unix(sshd:session): session closed for user root
secure:Oct  6 01:50:43 localhost sshd[2096]: pam_unix(sshd:session): session opened for user root by (uid=0)
secure-20180805:Aug  4 19:11:33 localhost sshd[5013]: pam_unix(sshd:session): session opened for user root b
y (uid=0)
secure-20180805:Aug  5 02:32:04 localhost sshd[5473]: pam_unix(sshd:session): session opened for user root b
y (uid=0)
secure-20180805:Aug  5 02:53:51 localhost su: pam_unix(su-l:session): session opened for user nglinux by roo
secure-20180805:Aug  5 02:54:58 localhost su: pam_unix(su-l:session): session closed for user nglinux
secure-20180825:Aug  5 21:36:23 localhost sshd[5473]: pam_unix(sshd:session): session closed for user root
secure-20180825:Aug  5 21:36:24 localhost sshd[5013]: pam_unix(sshd:session): session closed for user root
secure-20180825:Aug  5 21:36:30 localhost sshd[3818]: pam_unix(sshd:session): session closed for user root
secure-20180825:Aug  6 00:42:57 localhost sshd[7060]: pam_unix(sshd:session): session opened for user root b
y (uid=0)
secure-20180825:Aug  6 19:12:57 localhost sshd[3864]: pam_unix(sshd:session): session opened for user root b
y (uid=0)
secure-20180825:Aug 10 06:03:53 localhost pam: gdm-password: pam_unix(gdm-password:auth): authentication fai
lure; logname= uid=0 euid=0 tty=:0 ruser= rhost=  user=nglinux

5. Understanding PAM Configuration File.

Lets have a look at /etc/pam.d/login file to understand it.

[root@nglinux pam.d]# cat login 
auth [user_unknown=ignore success=ok ignore=ignore default=bad]
auth       include      system-auth
account    required
account    include      system-auth
password   include      system-auth
# close should be the first session rule
session    required close
session    required
session    optional
# open should only be followed by sessions to be executed in the user context
session    required open
session    required
session    optional force revoke
session    include      system-auth
-session   optional
[root@nglinux pam.d]# 

In above configuration file, lets take one entry to understand.
type control module-path module-arguments
session required close

a. type:- session type PAM module is called.
b. control:- If its required, or optional, or we need to include it.
c. Module-path: It determines the path where this module is kept. Simply module name means module is kept in PAM modules directory.
d. Options:- If any options need to be passed to the module, we provide it here.

The default path of PAM modules is /lib/security/.

[root@nglinux pam.d]# ls /lib/security/           pam_filter       
[root@nglinux pam.d]# 

6. How PAM configuration linked to services in Linux ?

Lets have a look how the configuration is attached with services in Linux.
The PAM configuration file name is same as that of service name or binary name.

## For example:- login file is linked to login binary
[root@nglinux pam.d]# ls -l /bin/login 
-rwxr-xr-x. 1 root root 26768 Mar 22  2017 /bin/login

[root@nglinux pam.d]# ls -l /etc/pam.d/login 
-rw-r--r--. 1 root root 728 Mar 22  2017 /etc/pam.d/login

### Another example of atd service.
[root@nglinux pam.d]# service atd status
atd (pid  2191) is running...

[root@nglinux pam.d]# ls -l /etc/pam.d/atd 
-rw-r--r--. 1 root root 272 Mar 21  2017 /etc/pam.d/atd

[root@nglinux pam.d]# cat /etc/pam.d/atd
# The PAM configuration file for the at daemon
auth       required
auth       include     password-auth
account    required
account    include     password-auth
session    required
session    include     password-auth
[root@nglinux pam.d]# 

7. How PAM shared objects are linked with binaries ?

### For this we can list down the binaries linked and we can see the PAM Shared object is linked with the executable.
[root@nglinux pam.d]# ldd /usr/sbin/atd =>  (0x005d1000) => /lib/ (0x007cf000) => /lib/ (0x00498000) => /lib/ (0x0014c000) => /lib/ (0x0028e000) => /lib/ (0x00ab5000)
	/lib/ (0x80088000) => /lib/ (0x00fd6000) => /lib/ (0x00f08000) => /lib/ (0x00ed7000)

[root@nglinux pam.d]# ldd /bin/login =>  (0x00659000) => /lib/ (0x46ee1000) => /lib/ (0x46ef1000) => /lib/ (0x00be7000) => /lib/ (0x46ebb000) => /lib/ (0x008be000) => /lib/ (0x00a74000) => /lib/ (0x04a26000)
	/lib/ (0x8002f000) => /lib/ (0x0088c000)
[root@nglinux pam.d]# 

Configuration Change Warning

If you delete any configuration file(s) from your /etc/pam.d/* directory and/or /etc/pam.conf, then your SYSTEM WILL BE LOCKED.


8. Return Values of PAM Modules

In general a PAM module returns any of the following as return value.
a. PAM_SUCCESS : Access granted.
b. PAM_PERM_DENIED : Access not granted.
c. PAM_IGNORE : Ignore and do nothing.
d. PAM_ABORT : Abort due to less information.
e. PAM_USER_UNKNOWN : User not known.

There is a lot more in PAM, each and every module has different implementation and each of it needs to be studied to understand it better.

We limit our initial PAM discussion here.

Do post your useful comments or feedback below.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments