Creating or modifying a PAM configuration requires at least a basic understanding of the available PAM modules. If you check your existing PAM configuration files, you’re likely to see quite a range of module calls, and modifying them to get the results you expect can be tricky if you don’t understand what the existing modules do.
Some PAM modules can be called for only some management groups. Others can be called as part of a stack for any management group.
PAM ships with quite a few different modules. Table A-2 summarizes those that you’re most likely to encounter in your existing configuration files. Note that, although some modules directly relate to password handling, others don’t; they’re used to display information to users, set environment variables, and so on. For these modules, PAM is simply a convenient tool for accomplishing their goals. Such modules may not affect the login process at all.
Table A-2. Common standard PAM modules
|
Module filename |
Management groups |
Common arguments |
Description |
|---|---|---|---|
|
|
|
|
Implements the traditional Unix (and Linux) authentication, based on
|
|
|
|
|
A variant on |
|
|
|
|
This module is an alternative way to authenticate against NT domain
controllers to that described in Chapter 7. It
uses the |
|
|
|
- |
Blocks root access to the login
service unless the environment variable |
|
|
|
- |
Reads |
|
|
|
|
If |
|
|
|
|
Prints a warning if the user’s home directory or
certain other files are world-writable or if they’re
owned by another user. If the |
|
|
|
|
Sets environment variables for the login session, based on the
contents of the configuration file
( |
|
|
|
|
Checks for mail in the specified directory and notifies the user if
any is present. If |
|
|
|
|
Displays information on the user’s last login. The
module’s options tell it what information to omit
from this display. It maintains last login information in the
|
|
|
|
|
Displays the contents of the message of the day (MOTD) file, which is
|
|
|
|
- |
Always indicates a failure; useful at the end of certain stacks or as part of a default service to eliminate the risk of an unauthorized login due to misconfiguration. |
|
|
|
|
Places limits, described in the
|
|
|
|
|
Creates a home directory for users if one doesn’t
already exist, using the specified skeleton ( |
|
|
|
|
Uses |
|
|
|
|
Performs extra checks on password changes, as defined in
|
|
|
|
|
Adds checks for various features, such as passwords that have been
used in the past or passwords that are too simple, to password-change
interactions. Uses the libcrack library and a
system dictionary ( |
|
|
|
|
Calls a stack for the specified |
Not all the modules mentioned in Table A-2 ship
with all Linux distributions. These modules are all present and used
in the default installations of at least one major distribution,
though, with the exception of pam_mkhomedir.so.
This module ships with all the major distributions but
isn’t used by default. It is, however, extremely
useful with NT domain and LDAP add-on PAM modules.
Some modules accept parameters that are common to other modules. These common parameters include:
debug
Although it’s not mentioned in Table A-2, this parameter causes most modules to dump extra debugging information to your system logfiles.
try_first_pass
Used in auth stacks, this option causes a module
to try to use a password collected by a previous module for
authentication. If this password fails, the module prompts the user
again. Using this option on the second and subsequent
password-checking modules can eliminate multiple password requests
when you try to log in.
use_first_pass
This parameter works much like try_first_pass, but
it causes the module that uses it to not request
a password if the one it’s given from a prior module
fails.
nullok
Most modules that handle passwords refuse null passwords (that is, passwords of zero length). This option tells these modules that null passwords are acceptable. (For authentication, of course, the authentication database must contain a null password; this option doesn’t bypass the password check.)
likeauth
This parameter causes the module to return the same value when called as a credential-setting module as an authentication module. This practice helps PAM navigate the module stack most efficiently.
shadow
If this option is present, the module takes extra care to maintain a system with shadow passwords. In particular, it better handles password aging, expiration, and similar information.
use_authtok
This option causes a module in a password stack to
use the password given to a previous module in a stack.
Linux distributions vary substantially in how they build PAM stacks
from these modules. If you check two distributions’
files, you’ll probably find they call modules using
different options, and they may call different sets of modules. Even
within a distribution, different services may call different modules,
even when the services are similar in function. Ultimately, though,
most PAM stacks call pam_unix.so or
pam_unix2.so, either directly for each service
or indirectly via pam_stack.so. This is the most
important PAM module, especially for logins.
Chapters
Chapter 7, Chapter 8, and Chapter 9 present information on PAM modules that can be
used in addition to or instead of the standard modules. In
particular, these modules can replace or supplement
pam_unix.so or
pam_unix2.so. If you check the Internet, you can
find still more PAM modules.
As described in the relevant chapters, there’s more to adding support for most network authentication modules than simply configuring PAM. These modules typically rely on external configuration files to point them to their authentication servers. Sometimes you must configure the server to accept authentication requests from your Linux system or take other special steps to get the system to work.
When you add new PAM modules for authentication, you should first
decide where to add them. If your distribution uses the
pam_stack.so module, you should modify the stack
that it references—typically
/etc/pam.d/system-auth. If your distribution
doesn’t use this module, however, you may need to
modify the configuration files for all the services that should use
the new PAM module. For login services (login,
xdm, sshd, and so on), you
need to add auth and account
lines:
auth sufficient /lib/security/pam_winbind.so try_first_pass account sufficient /lib/security/pam_winbind.so
Of course, the name of the module you call depends on what
you’re adding. Add the auth line
to the existing auth stack just after the line
that references pam_unix.so, and add the
account line just after the existing
account line. This placement causes PAM to check
the new service after checking the local account database. The
sufficient control flag tells PAM that if this
authentication succeeds, it doesn’t need to perform
additional authentication checks; however, if it fails, PAM falls
back on the local account database. The
try_first_pass option prevents PAM from prompting
for a password again should this happen; it delivers the password the
user entered first into the next authentication tool.
Some servers and login tools must be restarted before they’ll read the new PAM configuration files, so, if you forget to restart a server, you may think your change hasn’t worked, when in fact it simply hasn’t yet taken effect. Try to be methodical in your tests if you run into problems. Create some test accounts and take notes on the effects.
Be sure to test the effect of incorrect
logins—both nonexistent usernames and valid usernames with
invalid passwords. Some PAM configurations result in successful
logins even when invalid passwords, and sometimes even invalid
usernames, are entered. If you run into this problem, try adding a
required call to pam_deny.so
and make the actual authentication modules
sufficient.
For password-changing services, such as passwd,
your concerns are a bit different from those for login services.
Depending on your needs, you might consider doing any of several
things:
Adding a new entry to the password stack causes
the passwd program to prompt for two password
changes: one for the local Unix password database and again for the
new service you’ve added.
Adding a new entry to the password stack and using
the options use_authtok or
use_first_pass with the second call causes both
systems to use the password you enter the first time. You may need to
make both these entries sufficient rather than
required.
Replacing the existing call to pam_unix.so or
pam_unix2.so causes a single prompt for a
password change using the new service, leaving the local password (if
it exists) untouched.
Not changing the password stack causes only the local account to change, if it exists. Users need to use tools specific to their new authentication system, such as smbpasswd for an NT domain controller, to change their network passwords.
As if these concerns weren’t enough, a further complication is root’s power to change normal users’ passwords. Network authentication tools typically provide strong protections against anybody but the user or the password server’s administrator from changing passwords. A local root account is unlikely to have this power, so chances are you’ll need to use the administrative database’s tools to make these changes.