<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://commons.oreilly.com/wiki/index.php?title=Linux_in_a_Windows_World/Appendixes/Configuring_PAM&amp;action=history&amp;feed=atom</id>
		<title>Linux in a Windows World/Appendixes/Configuring PAM - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://commons.oreilly.com/wiki/index.php?title=Linux_in_a_Windows_World/Appendixes/Configuring_PAM&amp;action=history&amp;feed=atom"/>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Linux_in_a_Windows_World/Appendixes/Configuring_PAM&amp;action=history"/>
		<updated>2013-05-23T16:27:01Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.11.0</generator>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Linux_in_a_Windows_World/Appendixes/Configuring_PAM&amp;diff=9563&amp;oldid=prev</id>
		<title>Docbook2Wiki: Initial conversion from Docbook</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Linux_in_a_Windows_World/Appendixes/Configuring_PAM&amp;diff=9563&amp;oldid=prev"/>
				<updated>2008-03-11T23:06:43Z</updated>
		
		<summary type="html">&lt;p&gt;Initial conversion from Docbook&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 23:06, 11 March 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;</summary>
		<author><name>Docbook2Wiki</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Linux_in_a_Windows_World/Appendixes/Configuring_PAM&amp;diff=8785&amp;oldid=prev</id>
		<title>Docbook2Wiki: Initial conversion from Docbook</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Linux_in_a_Windows_World/Appendixes/Configuring_PAM&amp;diff=8785&amp;oldid=prev"/>
				<updated>2008-03-11T21:46:06Z</updated>
		
		<summary type="html">&lt;p&gt;Initial conversion from Docbook&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Linux in a Windows World/TOC}}&lt;br /&gt;
Modern Linux distributions rely on the Pluggable Authentication Modules system for authentication. [[Linux in a Windows World/Centralized Authentication Tools|Part III]] of this book describes three network authentication tools, all of which can be used in conjunction with PAM to provide authentication for arbitrary servers and other programs that require authentication. In order to avoid duplicating content, therefore, this appendix describes PAM in detail; [[Linux in a Windows World/Centralized Authentication Tools|Part III]] provides a much briefer description of how PAM interacts with the relevant servers.&lt;br /&gt;
&lt;br /&gt;
In order to get the most out of PAM, it helps to begin with some background—what PAM is, what it can do, why it's used, and so on. You must also understand the PAM configuration file format; PAM configuration involves editing one or more of these files. From there, knowing something about individual PAM modules, including both the standard ones and those described elsewhere in this book, will help you create an appropriate configuration. Finally, some examples of working PAM configurations will help you understand PAM and provide models you can adapt for your own use.&lt;br /&gt;
&lt;br /&gt;
== PAM Principles ==&lt;br /&gt;
&lt;br /&gt;
In Linux's early days, every server or other tool that had to authenticate users did so by reading ''/etc/password'', the traditional Unix account file. This approach was easy to implement, but it had several problems. One of these was that the file, and hence the encrypted password, had to be readable by all users, making it vulnerable to cracking. Another problem is that changes to authentication methods, such as new password-encryption systems, required changes to all the programs that could authenticate users. This problem would result in a nightmarish tangle of upgrades should an administrator ever want to change the authentication system.&lt;br /&gt;
&lt;br /&gt;
PAM is designed to solve these problems. PAM solves the problem of world readability of ''/etc/passwd'' by implementing a system known as ''shadow passwords'', in which passwords are moved out of ''/etc/passwd'' and into a file that can be read only by ''root''—typically ''/etc/shadow'' on Linux systems. (Shadow passwords can be implemented without PAM, but today PAM is the tool that does it on all major Linux distributions.) PAM helps minimize the pain of changing authentication systems by working as a layer between the tools that authenticate users and the account database. Instead of accessing ''/etc/passwd'' directly, programs consult PAM, which accesses ''/etc/passwd''. Thus, if the format of data in ''/etc/passwd'' changes, individual servers don't need to be rewritten or even recompiled; only PAM must change. Indeed, PAM can be changed to support authentication systems that don't even consult ''/etc/passwd''. It's this feature of PAM that Winbind, LDAP authentication, and some Kerberos tools use. Rather than consult ''/etc/passwd'', PAM consults the appropriate network authentication tool.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
In addition to PAM, Linux relies on another software component, the Name Service Switch, for account information. Rather than authentication information, though, NSS provides more mundane information, such as a mapping of UIDs to usernames and the account's default shell. Like PAM, NSS is designed in a modular way and sits between applications that ask for this information and the actual account databases. Although you may think in terms of authentication, which is what PAM provides, this ancillary information is just as important, so you must configure NSS to link to your authentication system. The chapters on Winbind and LDAP describe configuring NSS to work with these tools, but Kerberos provides no NSS interface, which is a limitation of Kerberos if you want a network authentication system to handle all your account information.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In practice, PAM is a modular tool: it consults libraries to handle various parts of the authentication procedure. You tell PAM which libraries to consult with the help of the PAM configuration files, which are described in the next section. Thus, the overall authentication system, and its equivalent in pre-PAM days, are depicted in [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-FIG-1|Figure A-1]]. PAM's modular nature is manifested in this figure by the fact that PAM is shown accessing three independent authentication tools—the ''/etc/passwd'' file, an NT domain controller, and an LDAP server. A default configuration is likely to be simpler than this, but if you want to use a network authentication tool, chances are you'll leave the old-style ''/etc/passwd'' authentication intact as a backup and to provide information for accounts you might not want to define using a centralized system, such as the ''root'' account.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;linuxwinworld-APP-A-FIG-1&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure A-1. PAM distances servers and other programs that require authentication from authentication implementations, increasing flexibility—and complexity'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Linux in a Windows World_I__tt277.png|PAM distances servers and other programs that require authentication from authentication implementations, increasing flexibility—and complexity]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In practice, PAM configuration is even more complex than [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-FIG-1|Figure A-1]] suggests, for three reasons:&lt;br /&gt;
&lt;br /&gt;
* PAM provides management features beyond those related to account authentication. In particular, it supports authentication (verifying that users are who they claim to be), account management (checking for expired accounts, the right to use a particular server, and so on), session management (login and logout housekeeping), and password changes. Each management system must be configured individually; for instance, the modules called in service of authentication may be different than those required for session management.&lt;br /&gt;
* A single act, such as logging in, may require multiple PAM modules. For instance, many PAM login configurations call a module called ''pam_deny.so'', which explicitly denies access to the system if no earlier module has explicitly granted access. You can even tack on modules that aren't directly related to authentication, such as modules that display login notices.&lt;br /&gt;
* Each program that requires PAM's services may be configured individually. For instance, you might want to use one set of options for authenticating users for console logins and another for authenticating users to use the ''su'' command to change their effective UID numbers.&lt;br /&gt;
&lt;br /&gt;
== The PAM Configuration File Format ==&lt;br /&gt;
&lt;br /&gt;
Configuring PAM means editing its configuration files. The format of these files is fairly simple, but these files use a number of options that aren't immediately obvious to the uninitiated. You must also know something about how the PAM configuration file works with multiple modules. These modules can also interact in unintuitive ways.&lt;br /&gt;
&lt;br /&gt;
=== PAM Configuration Files and Fields ===&lt;br /&gt;
&lt;br /&gt;
In order to implement its design goals, PAM uses one or more configuration files: either a file called ''/etc/pam.conf'' or files in the ''/etc/pam.d'' directory named after the particular systems they control. The ''/etc/pam.d'' directory is more common in Linux; this approach enables packages to add files to the directory for their services, without having to modify ''/etc/pam.conf''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;warning&amp;quot;&amp;gt;&lt;br /&gt;
'''Warning'''&lt;br /&gt;
&lt;br /&gt;
When reconfiguring PAM, you can easily render your system unable to support logins. Thus, I recommend experimenting with one login server at a time, leaving yourself some way to log in should you create an inoperable system. For instance, experiment with the &amp;lt;tt&amp;gt;login&amp;lt;/tt&amp;gt; service and leave the &amp;lt;tt&amp;gt;gdm&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;xdm&amp;lt;/tt&amp;gt; service alone. Some distributions use the ''pam_stack.so'' module (described shortly) to control many login servers. With such a system, you may need to back up its original configuration file and leave a ''root'' session running to be sure you can undo any disastrous mistake without logging in anew.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ''/etc/pam.conf'' file entries are similar to the contents of files in ''/etc/pam.d''. The principle difference is that the ''/etc/pam.conf'' entries begin with a service name field, which is missing from individual service files. The overall format for the lines in ''/etc/pam.d'' files is:&lt;br /&gt;
&lt;br /&gt;
                   ''management_group  control_flag  module''  [''options'']&lt;br /&gt;
&lt;br /&gt;
Each field has a specific meaning:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;''management_group''&amp;lt;/tt&amp;gt;&lt;br /&gt;
: This field holds one of four keywords specifying the type of service it defines: &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; for authentication, &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; for account management, &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt; for session management, or &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; for password management. Most PAM configuration files have at least one line of each type.&lt;br /&gt;
;&amp;lt;tt&amp;gt;''control_flag''&amp;lt;/tt&amp;gt;&lt;br /&gt;
: This field describes how PAM should react to the success or failure of a module. Possible values are &amp;lt;tt&amp;gt;requisite&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;optional&amp;lt;/tt&amp;gt;. The meanings of these values are described in the next section. A more advanced syntax involves matching specific actions to the module's exact return value. This is flexible but tedious to configure (it involves 30 return codes and six possible actions), and so it isn't described in this book.&lt;br /&gt;
;&amp;lt;tt&amp;gt;''module''&amp;lt;/tt&amp;gt;&lt;br /&gt;
: This field is a pointer to the module file itself, sometimes with its complete path. (If the path is missing, PAM checks its modules directory, which is usually ''/lib/security''.)&lt;br /&gt;
;&amp;lt;tt&amp;gt;''options''&amp;lt;/tt&amp;gt;&lt;br /&gt;
: You can pass parameters to the module via the &amp;lt;tt&amp;gt;''options''&amp;lt;/tt&amp;gt; field on the module definition line. Some options are highly module-specific, but others are recognized by many modules. Some of these options are described in the [[Linux in a Windows World/Appendixes/Configuring PAM#Standard PAM Modules|Section A.3.1]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
This first field in the lines of ''pam.conf'', which is missing from the ''/etc/pam.d'' files in most Linux distributions, holds the name of the tool it configures, such as &amp;lt;tt&amp;gt;login&amp;lt;/tt&amp;gt; for the ''login'' service, or &amp;lt;tt&amp;gt;gdm&amp;lt;/tt&amp;gt; for the GDM GUI login tool. If your system uses files in ''/etc/pam.d'', the names of these files are typically the names that appear in this first column in a system that uses ''/etc/pam.conf''.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In addition to configuration lines, PAM configuration files can contain comments. These begin with a hash mark (&amp;lt;tt&amp;gt;#&amp;lt;/tt&amp;gt;). Entire lines can be comments, or comments can come at the end of a line that serves some other purpose.&lt;br /&gt;
&lt;br /&gt;
=== Module Stacks ===&lt;br /&gt;
&lt;br /&gt;
A configuration for a single authentication tool can combine several PAM modules. This happens in two ways. First, each of the four management groups (&amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt;) requires its own configuration. Second, with each management group, multiple modules can be called. When multiple modules are called, the result is referred to as a module ''stack''. For instance, a login service might have separate &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; stacks. These stacks are likely to have some modules in common (they perform different actions depending upon the calling stack), but each may also have some unique modules.&lt;br /&gt;
&lt;br /&gt;
Individual modules in a stack deliver return values that can be classified as ''failures'' or ''successes''. In this context, these terms don't refer to program bugs or the lack thereof, but to failures or successes in authentication or other actions. For instance, if a user enters the wrong password, an authentication module will fail.&lt;br /&gt;
&lt;br /&gt;
Modules in a stack are called in the order in which they're specified. This order is unimportant if all of the modules are of the &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; variety, but if you use other control flags—particularly &amp;lt;tt&amp;gt;requisite&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt;—order can become important, as described shortly.&lt;br /&gt;
&lt;br /&gt;
Understanding the operation of module stacks can be tricky, because the different control flags can have confusing implications. [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-TABLE-1|Table A-1]] summarizes the consequences of successes and failures of modules called with particular control flags.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;linuxwinworld-APP-A-TABLE-1&amp;quot;&amp;gt;&lt;br /&gt;
'''Table A-1. Consequences of control flags'''&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Control flag !! Module success result !! Module failure result&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;requisite&amp;lt;/tt&amp;gt; || Stack execution continues; stack may succeed or fail, depending on outcome of other modules || Stack execution terminates immediately; stack fails&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; || Stack execution continues; stack may succeed or fail, depending on outcome of other modules || Stack execution continues, but stack fails&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; || Stack execution terminates immediately, provided no prior &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; module has failed; stack succeeds (failure of a prior &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; module may cause stack failure, though) || Stack execution continues; stack may succeed or fail, depending on outcome of other modules&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;optional&amp;lt;/tt&amp;gt; || Stack execution continues; stack may succeed or fail, depending on outcome of other modules, unless other modules are missing or give inconclusive results, in which case the stack succeeds || Stack execution continues; stack may succeed or fail, depending on outcome of other modules, unless other modules are missing or give inconclusive results, in which case the stack fails&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These rules can become quite confusing in the event of conflicting outcomes. For instance, consider the following stack:&lt;br /&gt;
&lt;br /&gt;
 auth required   pam_unix.so try_first_pass&lt;br /&gt;
 auth sufficient pam_krb5.so try_first_pass&lt;br /&gt;
 auth required   pam_env.so&lt;br /&gt;
&lt;br /&gt;
For now, you need only know that the ''pam_unix.so'' and ''pam_krb5.so'' modules authenticate users, while ''pam_env.so'' sets environment variables but never returns a failure code. Because this stack provides two login modules, each with two possible outcomes, you must consider four possibilities—both succeed, both fail, ''pam_unix.so'' succeeds while ''pam_krb5.so'' fails, or ''pam_unix.so'' fails while ''pam_krb5.so'' succeeds. In practice, this stack as a whole succeeds if and only if ''pam_unix.so'' succeeds; if it fails, its &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; status overrides the &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; status of ''pam_krb5.so'', and if it succeeds, that success won't be overridden by a failure of the &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; ''pam_krb5.so''. What happens if the two authentication modules' order is reversed, though?&lt;br /&gt;
&lt;br /&gt;
 auth sufficient pam_krb5.so try_first_pass&lt;br /&gt;
 auth required   pam_unix.so try_first_pass&lt;br /&gt;
 auth required   pam_env.so&lt;br /&gt;
&lt;br /&gt;
In this case, because the &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; ''pam_krb5.so'' module comes first, its success bypasses the later &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; ''pam_unix.so'' module, so this stack succeeds if either module succeeds. A success of ''pam_krb5.so'', though, bypasses the ''pam_env.so'' module, which may not be desirable.&lt;br /&gt;
&lt;br /&gt;
== PAM Modules ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
Some PAM modules can be called for only some management groups. Others can be called as part of a stack for any management group.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Standard PAM Modules ===&lt;br /&gt;
&lt;br /&gt;
PAM ships with quite a few different modules. [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-TABLE-2|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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;linuxwinworld-APP-A-TABLE-2&amp;quot;&amp;gt;&lt;br /&gt;
'''Table A-2. Common standard PAM modules'''&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Module filename !! Management groups !! Common arguments !! Description&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_unix.so'' || &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;nullok&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;likeauth&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;shadow&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;try_first_pass&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;use_first_pass&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;use_authtok&amp;lt;/tt&amp;gt; || Implements the traditional Unix (and Linux) authentication, based on ''/etc/passwd'' and ''/etc/shadow'' files.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_unix2.so'' || &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;nullok&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;likeauth&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;shadow&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;try_first_pass&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;use_first_pass&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;use_authtok&amp;lt;/tt&amp;gt; || A variant on ''pam_unix.so'' that implements additional features, such as an ability to authenticate against a Network Information Service (NIS) server.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_smb_auth.so'' || &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;use_first_pass&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;nolocal&amp;lt;/tt&amp;gt; || This module is an alternative way to authenticate against NT domain controllers to that described in [[Linux in a Windows World/Centralized Authentication Tools/Using NT Domains for Linux Authentication|Chapter 7]]. It uses the ''/etc/pam_smb.conf'' configuration file.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_securetty.so'' || &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; || - || Blocks ''root'' access to the login service unless the environment variable &amp;lt;tt&amp;gt;PAM_TTY&amp;lt;/tt&amp;gt; is set to a string listed in the ''/etc/securetty'' file.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_time.so'' || &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; || - || Reads ''/etc/security/time.conf'', which specifies time-based access restriction rules.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_nologin.so'' || &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;successok&amp;lt;/tt&amp;gt; || If ''/etc/nologin'' exists, only ''root'' is permitted to log in, and all users are shown the contents of that file. If the file doesn't exist, the module has no effect, unless the &amp;lt;tt&amp;gt;successok&amp;lt;/tt&amp;gt; parameter is used, in which case the login succeeds (as if the module were called with a &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; control flag).&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_homecheck.so'' || &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;abort&amp;lt;/tt&amp;gt; || 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 &amp;lt;tt&amp;gt;abort&amp;lt;/tt&amp;gt; option is used, the login fails under these circumstances.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_env.so'' || &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;conffile=&amp;lt;/tt&amp;gt;&amp;lt;tt&amp;gt;''filename''&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;envfile=&amp;lt;/tt&amp;gt;&amp;lt;tt&amp;gt;''filename''&amp;lt;/tt&amp;gt; || Sets environment variables for the login session, based on the contents of the configuration file (''/etc/security/pam_env.conf'' by default).&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_mail.so'' || &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;dir=&amp;lt;/tt&amp;gt;&amp;lt;tt&amp;gt;''directory''&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;empty&amp;lt;/tt&amp;gt; || Checks for mail in the specified directory and notifies the user if any is present. If &amp;lt;tt&amp;gt;empty&amp;lt;/tt&amp;gt; is used, also informs the user when no mail is present.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_lastlog.so'' || &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;nodate&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;noterm&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;nohost&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;silent&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;never&amp;lt;/tt&amp;gt; || 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 ''/var/log/lastlog'' file.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_motd.so'' || &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;motd=&amp;lt;/tt&amp;gt;&amp;lt;tt&amp;gt;''filename''&amp;lt;/tt&amp;gt; || Displays the contents of the message of the day (MOTD) file, which is ''/etc/motd'' by default, upon a successful login.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_deny.so'' || &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; || - || 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.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_limits.so'' || &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;conf=&amp;lt;/tt&amp;gt;&amp;lt;tt&amp;gt;''filename''&amp;lt;/tt&amp;gt; || Places limits, described in the ''/etc/security/limits.conf'' or specified configuration file, on users' resource uses (memory, CPU time, etc.). Requires kernel support for resource limits.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_mkhomedir.so'' || &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;skel=&amp;lt;/tt&amp;gt;&amp;lt;tt&amp;gt;''directory''&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;umask=&amp;lt;/tt&amp;gt;&amp;lt;tt&amp;gt;''octal-umask''&amp;lt;/tt&amp;gt; || Creates a home directory for users if one doesn't already exist, using the specified skeleton (&amp;lt;tt&amp;gt;skel&amp;lt;/tt&amp;gt;) directory to populate the home directory with default configuration files and setting the directory's permissions based on the specified umask.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_access.so'' || &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;accessfile=&amp;lt;/tt&amp;gt;&amp;lt;tt&amp;gt;''filename''&amp;lt;/tt&amp;gt; || Uses ''/etc/security/access.conf'' or the specified access file to determine username/machine name pairs that are or aren't granted access—e.g., to deny ''root'' the right to log in from particular machines.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_pwcheck.so'' || &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;nullok&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;use_first_pass&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;use_authtok&amp;lt;/tt&amp;gt; || Performs extra checks on password changes, as defined in ''/etc/login.defs'', to improve security on user-selected passwords.&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_cracklib.so'' || &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;use_authtok&amp;lt;/tt&amp;gt; and others to set specific checks || 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 (''/usr/lib/cracklib_dict'').&lt;br /&gt;
|-&lt;br /&gt;
| ''pam_stack.so'' || &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;service=&amp;lt;/tt&amp;gt;&amp;lt;tt&amp;gt;''name''&amp;lt;/tt&amp;gt; || Calls a stack for the specified &amp;lt;tt&amp;gt;service&amp;lt;/tt&amp;gt;. Provides easier configuration; you need to modify only one PAM configuration file to implement PAM changes across all the services that call ''pam_stack.so''.&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
Not all the modules mentioned in [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-TABLE-2|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.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some modules accept parameters that are common to other modules. These common parameters include:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;debug&amp;lt;/tt&amp;gt;&lt;br /&gt;
: Although it's not mentioned in [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-TABLE-2|Table A-2]], this parameter causes most modules to dump extra debugging information to your system logfiles.&lt;br /&gt;
;&amp;lt;tt&amp;gt;try_first_pass&amp;lt;/tt&amp;gt;&lt;br /&gt;
: Used in &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
;&amp;lt;tt&amp;gt;use_first_pass&amp;lt;/tt&amp;gt;&lt;br /&gt;
: This parameter works much like &amp;lt;tt&amp;gt;try_first_pass&amp;lt;/tt&amp;gt;, but it causes the module that uses it to ''not'' request a password if the one it's given from a prior module fails.&lt;br /&gt;
;&amp;lt;tt&amp;gt;nullok&amp;lt;/tt&amp;gt;&lt;br /&gt;
: 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.)&lt;br /&gt;
;&amp;lt;tt&amp;gt;likeauth&amp;lt;/tt&amp;gt;&lt;br /&gt;
: 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.&lt;br /&gt;
;&amp;lt;tt&amp;gt;shadow&amp;lt;/tt&amp;gt;&lt;br /&gt;
: 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.&lt;br /&gt;
;&amp;lt;tt&amp;gt;use_authtok&amp;lt;/tt&amp;gt;&lt;br /&gt;
: This option causes a module in a &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; stack to use the password given to a previous module in a stack.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== Additional PAM Modules ===&lt;br /&gt;
&lt;br /&gt;
Chapters [[Linux in a Windows World/Centralized Authentication Tools/Using NT Domains for Linux Authentication|Chapter 7]], [[Linux in a Windows World/Centralized Authentication Tools/Using LDAP|Chapter 8]], and [[Linux in a Windows World/Centralized Authentication Tools/Kerberos Configuration and Use|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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; lines:&lt;br /&gt;
&lt;br /&gt;
 auth     sufficient  /lib/security/pam_winbind.so try_first_pass&lt;br /&gt;
 account  sufficient  /lib/security/pam_winbind.so&lt;br /&gt;
&lt;br /&gt;
Of course, the name of the module you call depends on what you're adding. Add the &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; line to the existing &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; stack just after the line that references ''pam_unix.so'', and add the &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; line just after the existing &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; line. This placement causes PAM to check the new service after checking the local account database. The &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; 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 &amp;lt;tt&amp;gt;try_first_pass&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; call to ''pam_deny.so'' and make the actual authentication modules &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
* Adding a new entry to the &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
* Adding a new entry to the &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; stack and using the options &amp;lt;tt&amp;gt;use_authtok&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;use_first_pass&amp;lt;/tt&amp;gt; with the second call causes both systems to use the password you enter the first time. You may need to make both these entries &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; rather than &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* 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.&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Sample PAM Configurations ==&lt;br /&gt;
&lt;br /&gt;
The preceding presentation is fairly abstract and may be hard to digest without some examples. Here, then, are some concrete examples, taken from working Linux distributions. These include a login service, a password service, and a system that uses an authentication stack.&lt;br /&gt;
&lt;br /&gt;
=== Typical Login Services ===&lt;br /&gt;
&lt;br /&gt;
Login services include the ''login'' program (used by the console and the Telnet server); the X Display Manager (XDM) and its KDE and GNOME counterparts, KDM and GDM; the SSH server; POP and IMAP mail servers; and the FTP server. Other tools that are similar, but that deviate a bit more, include the ''su'' and ''sudo'' commands and password-protected screensavers.&lt;br /&gt;
&lt;br /&gt;
[[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-EX-1|Example A-1]] shows the ''/etc/pam.d/login'' file from a Debian Linux system. (The original file has many comment lines, though, which [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-EX-1|Example A-1]] has omitted for brevity.) Because this is a login configuration, the most important sections of this file—from the perspective of an administrator wanting to change the system to use a network password database—are the &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; stacks. These stacks both contain calls to ''pam_unix.so'', as well as a few others that can restrict access in various ways or display information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;linuxwinworld-APP-A-EX-1&amp;quot;&amp;gt;&lt;br /&gt;
'''Example A-1. Sample PAM login service configuration'''&lt;br /&gt;
&lt;br /&gt;
 auth       requisite  pam_securetty.so&lt;br /&gt;
 auth       requisite  pam_nologin.so&lt;br /&gt;
 auth       required   pam_env.so&lt;br /&gt;
 auth       required   pam_unix.so nullok&lt;br /&gt;
 &lt;br /&gt;
 account    requisite  pam_time.so&lt;br /&gt;
 account    required   pam_unix.so&lt;br /&gt;
 &lt;br /&gt;
 session    required   pam_unix.so&lt;br /&gt;
 session    optional   pam_lastlog.so&lt;br /&gt;
 session    optional   pam_motd.so&lt;br /&gt;
 session    optional   pam_mail.so standard noenv&lt;br /&gt;
 &lt;br /&gt;
 password   required   pam_unix.so nullok min=6 max=255 md5&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To modify [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-EX-1|Example A-1]] to use an LDAP server (just as an example), you would add &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; references to the ''pam_ldap.so'' module to the &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; stacks just ''before'' the existing ''pam_unix.so'' calls. You may also want to add a call to the ''pam_mkhomedir.so'' module to the &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt; stack, in order to create users' home directories if they don't already exist. [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-EX-2|Example A-2]] presents all of these changes, with the changed and added material shown in bold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;linuxwinworld-APP-A-EX-2&amp;quot;&amp;gt;&lt;br /&gt;
'''Example A-2. Sample PAM login service configuration with LDAP support'''&lt;br /&gt;
&lt;br /&gt;
 auth       requisite  pam_securetty.so&lt;br /&gt;
 auth       requisite  pam_nologin.so&lt;br /&gt;
 auth       required   pam_env.so&lt;br /&gt;
 '''auth       sufficient pam_ldap.so'''&lt;br /&gt;
 auth       required   pam_unix.so nullok '''try_first_pass'''&lt;br /&gt;
 &lt;br /&gt;
 account    requisite  pam_time.so&lt;br /&gt;
 '''account    sufficient pam_ldap.so'''&lt;br /&gt;
 account    required   pam_unix.so&lt;br /&gt;
 &lt;br /&gt;
 session    required   pam_unix.so&lt;br /&gt;
 session    optional   pam_lastlog.so&lt;br /&gt;
 session    optional   pam_motd.so&lt;br /&gt;
 session    optional   pam_mail.so standard noenv&lt;br /&gt;
 '''session    required   pam_mkhomedir.so skel=/etc/skel umask=0027'''&lt;br /&gt;
 &lt;br /&gt;
 password   required   pam_unix.so nullok min=6 max=255 md5&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Several variants on these changes are possible. For instance, instead of adding ''pam_ldap.so'' before ''pam_unix.so'', you can add a &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; call to ''pam_ldap.so'' after ''pam_unix.so'', but this requires changing the status of ''pam_unix.so'' from &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; and also associating the &amp;lt;tt&amp;gt;try_first_pass&amp;lt;/tt&amp;gt; option with ''pam_ldap.so''. This order reversal can reduce network traffic if significant numbers of users have locally defined accounts. Debian's configuration doesn't call any modules in the &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; stacks after the ''pam_unix.so'' call, but some distributions do make such calls. For them, the specification of which module is called as &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; has implications for the conditions under which these subsequent modules are called.&lt;br /&gt;
&lt;br /&gt;
Yet another option is to set the calls to both ''pam_unix.so'' and ''pam_ldap.so'' to &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; and add calls to ''pam_deny.so'' to the ends of these stacks. This approach may be less confusing to configure because the order of modules becomes a bit less important; however, a successful login using any of the &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; modules then bypasses all subsequent modules in the stack, which may be undesirable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
If you want modules that must be placed after the actual password-checking modules to be called in all cases, you may want to look into using the ''pam_stack.so'' module. You can then place your actual password-checking calls in a substack that returns a single value, call ''pam_stack.so'' as a &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; module, and have modules that appear after this call in your individual service definitions execute no matter what tool actually authenticated your users.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unless your system uses the ''pam_stack.so'' module, you should make changes similar to these on all of the PAM modules corresponding to the login and other authentication services you use. Of course, your files aren't likely to be identical to this one unless you use Debian—and even then, other Debian PAM files aren't identical to this one. You therefore need to adjust your changes to suit your own files.&lt;br /&gt;
&lt;br /&gt;
One login server requires a bit of extra attention: SSH. This server sometimes doesn't work well with PAM authentication. If you can't seem to get your SSH server to use your new authentication tool, you may need to set one of two options in the ''/etc/ssh/sshd_config'' file on the SSH server system:&lt;br /&gt;
&lt;br /&gt;
 UsePAM yes&lt;br /&gt;
 UsePrivilegeSeparation no&lt;br /&gt;
&lt;br /&gt;
I recommend trying &amp;lt;tt&amp;gt;UsePAM&amp;lt;/tt&amp;gt; &amp;lt;tt&amp;gt;yes&amp;lt;/tt&amp;gt; first. If that fails, try the second option. One of the two should get SSH to play nicely with PAM.&lt;br /&gt;
&lt;br /&gt;
=== Password Services ===&lt;br /&gt;
&lt;br /&gt;
The ''/etc/pam.d/passwd'' file on most systems controls the ''passwd'' program's interactions with PAM. [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-EX-3|Example A-3]] shows a sample file from a SuSE system. This file is a bit simpler than a typical login service definition.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;linuxwinworld-APP-A-EX-3&amp;quot;&amp;gt;&lt;br /&gt;
'''Example A-3. Sample PAM password service configuration'''&lt;br /&gt;
&lt;br /&gt;
 auth       required   pam_unix2.so    nullok&lt;br /&gt;
 &lt;br /&gt;
 account    required   pam_unix2.so&lt;br /&gt;
 &lt;br /&gt;
 password   required   pam_pwcheck.so  nullok&lt;br /&gt;
 password   required   pam_unix2.so    nullok use_first_pass use_authtok&lt;br /&gt;
 &lt;br /&gt;
 session    required   pam_unix2.so&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose that you want to enable users to change passwords on their local accounts if they exist or on their LDAP accounts if they exist. PAM can be rather picky about such arrangements; the ''passwd'' command requires use of several PAM stacks to do its work, from authentication through to the actual password change. Thus, you must add references to ''pam_ldap.so'' to three stacks. [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-EX-4|Example A-4]] shows the result, with changed or added parts highlighted in bold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;linuxwinworld-APP-A-EX-4&amp;quot;&amp;gt;&lt;br /&gt;
'''Example A-4. Sample PAM password service configuration with LDAP support'''&lt;br /&gt;
&lt;br /&gt;
                      '''auth       sufficient pam_ldap.so'''&lt;br /&gt;
 auth       required   pam_unix2.so    nullok '''use_first_pass'''&lt;br /&gt;
 &lt;br /&gt;
                      '''account    sufficient pam_ldap.so'''&lt;br /&gt;
 account    required   pam_unix2.so&lt;br /&gt;
 &lt;br /&gt;
 password   required   pam_pwcheck.so  nullok&lt;br /&gt;
 '''password   optional   pam_ldap.so     use_first_pass use_authtok'''&lt;br /&gt;
 password   required   pam_unix2.so    nullok use_first_pass use_authtok&lt;br /&gt;
 &lt;br /&gt;
 session    required   pam_unix2.so&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration enables users to change their passwords much as they ordinarily do, by typing &amp;lt;tt&amp;gt;'''passwd'''&amp;lt;/tt&amp;gt; and answering the usual password-changing prompts. Making the actual &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; call to ''pam_ldap.so'' &amp;lt;tt&amp;gt;optional&amp;lt;/tt&amp;gt; changes the LDAP password if it exists but doesn't cause the operation to fail if the LDAP password doesn't exist. Thus, this configuration works for users who are defined locally, defined on the LDAP server, or both. (The &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; nature of the &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; stack call to ''pam_unix2.so'' would seem likely to cause a failure if the account isn't defined locally, but in practice, this isn't a problem.)&lt;br /&gt;
&lt;br /&gt;
This configuration does have one drawback: the ''root'' user is prompted for the LDAP password of users, if they have LDAP accounts, before being allowed to change them. As a practical matter, this means that system administrators must use LDAP tools, rather than the ''passwd'' command, to change users' forgotten passwords or to set passwords on new accounts.&lt;br /&gt;
&lt;br /&gt;
Of course, you can try variants on these changes. For instance, you can require users to have LDAP accounts; however, this might be undesirable if you want to maintain some local accounts (such as ''root'') independent of the LDAP server. Alternatively, if you make the ''pam_ldap.so'' call in the &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; stack &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt;, users with both LDAP and local accounts can change only their LDAP passwords.&lt;br /&gt;
&lt;br /&gt;
=== An Authentication Stack ===&lt;br /&gt;
&lt;br /&gt;
Some distributions, such as Red Hat, Fedora, and Gentoo, now use the ''pam_stack.so'' module to place common authentication options in a single file. This approach can greatly simplify PAM configuration because you need to change only one file. [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-EX-5|Example A-5]] shows the ''/etc/pam.d/system-auth'' file from a Gentoo system. (The original includes the complete paths to the library modules; [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-EX-5|Example A-5]] omits these paths to keep line lengths manageable.) In principle, this file is a combination of other PAM configuration files, defining basic features used by all of them. This file shouldn't get too specific, though; options that should apply only to a few authentication tools should go in those tools' configuration files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;linuxwinworld-APP-A-EX-5&amp;quot;&amp;gt;&lt;br /&gt;
'''Example A-5. Sample PAM stack service configuration'''&lt;br /&gt;
&lt;br /&gt;
 auth       required   pam_env.so&lt;br /&gt;
 auth       sufficient pam_unix.so likeauth nullok&lt;br /&gt;
 auth       required   pam_deny.so&lt;br /&gt;
 &lt;br /&gt;
 account    required   pam_unix.so&lt;br /&gt;
 &lt;br /&gt;
 password   required   pam_cracklib.so retry=3&lt;br /&gt;
 password   sufficient pam_unix.so nullok md5 shadow use_authtok&lt;br /&gt;
 password   required   pam_deny.so&lt;br /&gt;
 &lt;br /&gt;
 session    required   pam_limits.so&lt;br /&gt;
 session    required   pam_unix.so&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To modify [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-EX-5|Example A-5]] to use LDAP in addition to the local account database, you must add references to the ''pam_ldap.so'' module in the &amp;lt;tt&amp;gt;auth&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;account&amp;lt;/tt&amp;gt; stacks. For the latter, you may also want to change the existing call to ''pam_unix.so'' to &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; and add a &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; call to ''pam_deny.so'' to prevent too-easy bypassing of account-maintenance requirements, should you implement any. You may also want to add a call to the ''pam_mkhomedir.so'' module in the &amp;lt;tt&amp;gt;session&amp;lt;/tt&amp;gt; stack; however, you might prefer putting this call in the individual server PAM modules to better control home directory creation. Once all the changes are made, the result looks like [[Linux in a Windows World/Appendixes/Configuring PAM#linuxwinworld-APP-A-EX-6|Example A-6]], which shows changed or added material in bold.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;linuxwinworld-APP-A-EX-6&amp;quot;&amp;gt;&lt;br /&gt;
'''Example A-6. Sample PAM stack service configuration with LDAP support'''&lt;br /&gt;
&lt;br /&gt;
 auth       required   pam_env.so&lt;br /&gt;
 '''auth       sufficient pam_ldap.so'''&lt;br /&gt;
 auth       sufficient pam_unix.so likeauth nullok '''use_first_pass'''&lt;br /&gt;
 auth       required   pam_deny.so&lt;br /&gt;
 &lt;br /&gt;
 '''account    sufficient pam_ldap.so'''&lt;br /&gt;
 account    '''sufficient''' pam_unix.so&lt;br /&gt;
 '''account    required   pam_deny.so'''&lt;br /&gt;
 &lt;br /&gt;
 password   required   pam_cracklib.so retry=3&lt;br /&gt;
 password   sufficient pam_unix.so nullok md5 shadow use_authtok&lt;br /&gt;
 password   required   pam_deny.so&lt;br /&gt;
 &lt;br /&gt;
 session    required   pam_limits.so&lt;br /&gt;
 session    required   pam_unix.so&lt;br /&gt;
 '''session    required   pam_mkhomedir.so skel=/etc/skel/ umask=0022'''&lt;br /&gt;
                   &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;warning&amp;quot;&amp;gt;&lt;br /&gt;
'''Warning'''&lt;br /&gt;
&lt;br /&gt;
Fedora and Red Hat autogenerate their ''/etc/pam.d/system-auth'' files using a tool called ''authconfig'' or its GUI equivalent, ''system-config-authentication''. If you make changes to the raw PAM file, they may be wiped out if you run this tool. Thus, you might want to modify the file by using the configuration tool, rather than editing it directly. This tool also enables you to set configuration options for specific network authentication tools, such as locating your NT domain controller or LDAP server.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As always, many variants on this set of changes are possible. For instance, you can make changes to the &amp;lt;tt&amp;gt;password&amp;lt;/tt&amp;gt; stack analogous with those described in the earlier [[Linux in a Windows World/Appendixes/Configuring PAM#Password Services|Section A.4.2]]; however, I find that implementing these changes directly in the ''passwd'' file often produces better results.&lt;br /&gt;
&lt;br /&gt;
This example configuration uses &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; calls to several modules along with ''pam_deny.so'' to block accesses that fail all of these calls. This approach works well when you have no calls subsequent to the &amp;lt;tt&amp;gt;sufficient&amp;lt;/tt&amp;gt; calls in a stack. In the case of a stacked configuration like this, its calling stack can then place additional module calls after the call to ''pam_stack.so'', no matter how the stack module exits, if the calling stack calls ''pam_stack.so'' as a &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;requisite&amp;lt;/tt&amp;gt; module.&lt;br /&gt;
&lt;br /&gt;
Changing a stack module's configuration doesn't mean you can't change individual servers' configurations. You can make general changes to ''/etc/pam.d/system-auth'' and then add other calls to the configuration files for ''login'', KDM, ''su'', and other tools, as you see fit.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
PAM is a powerful tool for managing authentication options in Linux. As a modular tool, PAM is easily expanded—at least, easily when compared to recompiling all of your servers and other programs that require authentication. PAM is a very flexible tool, and some of this flexibility manifests itself in a plethora of options, some of which interact in peculiar ways. Understanding at least the more common of these options will help you adapt your PAM configuration to suit your needs, including adding network authentication tools such as NT domain controllers, LDAP servers, and Kerberos realms to your system. Actually creating a working configuration is likely to take some trial and error, but the examples presented here should set you on the right path.&lt;/div&gt;</summary>
		<author><name>Docbook2Wiki</name></author>	</entry>

	</feed>