Table of Contents

Ubuntu - PAM - Configure PAM Advanced

To write more complex PAM rules, you can use valid control-flags in the following form:

type [value1=action1 value2=action2 …] module module-arguments

Where valueN corresponds to the return code from the function invoked in the module for which the line is defined.

You can find supported values from the on-line PAM Administrator’s Guide.

A special value is default, which implies all valueN’s not mentioned explicitly.

The actionN can take one of the following forms:

Each of the four keywords: required; requisite; sufficient; and optional, have an equivalent expression in terms of the […] syntax, which allow you to write more complicated rules and they are:

The following is an example from a modern CentOS 7 system. Let’s consider these rules from the /etc/pam.d/postlogin PAM file:

#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
session     [success=1 default=ignore] pam_succeed_if.so service !~ gdm* service !~ su* quiet
session     [default=1]   pam_lastlog.so nowtmp showfailed
session     optional      pam_lastlog.so silent noupdate showfailed

Here is another example configuration from the /etc/pam.d/smartcard-auth PAM file:

#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        [success=done ignore=ignore default=die] pam_pkcs11.so nodebug wait_for_card
auth        required      pam_deny.so
 
account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
account     required      pam_permit.so
 
password    required      pam_pkcs11.so
 
session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
-session     optional      pam_systemd.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so

Info

For more information, see the pam.d man page:

man pam.d

A comprehensive description of the Configuration file syntax and all PAM modules can be found in the documentation for Linux-PAM.


Summary

PAM is a powerful high-level API that allows programs that rely on authentication to authentic users to applications in a Linux system.

It’s powerful but very challenging to understand and use.