1 <?xml version='1.0' encoding='UTF-8'?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
6 <title>The Linux-PAM System Administrators' Guide</title>
9 <firstname>Andrew G.</firstname>
10 <surname>Morgan</surname>
11 <email>morgan@kernel.org</email>
14 <firstname>Thorsten</firstname>
15 <surname>Kukuk</surname>
16 <email>kukuk@thkukuk.de</email>
19 <releaseinfo>Version 0.99.6.4, 20. September 2006</releaseinfo>
22 This manual documents what a system-administrator needs to know about
23 the <emphasis remap='B'>Linux-PAM</emphasis> library. It covers the
24 correct syntax of the PAM configuration file and discusses strategies
25 for maintaining a secure system.
30 <chapter id='sag-introductoin'>
31 <title>Introduction</title>
33 <emphasis remap='B'>Linux-PAM</emphasis> (Pluggable Authentication
34 Modules for Linux) is a suite of shared libraries that enable the
35 local system administrator to choose how applications authenticate users.
38 In other words, without (rewriting and) recompiling a PAM-aware
39 application, it is possible to switch between the authentication
40 mechanism(s) it uses. Indeed, one may entirely upgrade the local
41 authentication system without touching the applications themselves.
44 Historically an application that has required a given user to be
45 authenticated, has had to be compiled to use a specific authentication
46 mechanism. For example, in the case of traditional UN*X systems, the
47 identity of the user is verified by the user entering a correct
48 password. This password, after being prefixed by a two character
49 ``salt'', is encrypted (with crypt(3)). The user is then authenticated
50 if this encrypted password is identical to the second field of the
51 user's entry in the system password database (the
52 <filename>/etc/passwd</filename> file). On such systems, most if
53 not all forms of privileges are granted based on this single
54 authentication scheme. Privilege comes in the form of a personal
55 user-identifier (UID) and membership of various groups. Services and
56 applications are available based on the personal and group identity
57 of the user. Traditionally, group membership has been assigned based
58 on entries in the <filename>/etc/group</filename> file.
61 It is the purpose of the <emphasis remap='B'>Linux-PAM</emphasis>
62 project to separate the development of privilege granting software
63 from the development of secure and appropriate authentication schemes.
64 This is accomplished by providing a library of functions that an
65 application may use to request that a user be authenticated. This
66 PAM library is configured locally with a system file,
67 <filename>/etc/pam.conf</filename> (or a series of configuration
68 files located in <filename>/etc/pam.d/</filename>) to authenticate a
69 user request via the locally available authentication modules. The
70 modules themselves will usually be located in the directory
71 <filename>/lib/security</filename> or
72 <filename>/lib64/security</filename> and take the form of dynamically
73 loadable object files (see <citerefentry>
74 <refentrytitle>dlopen</refentrytitle><manvolnum>3</manvolnum>
79 <chapter id="sag-text-conventions">
80 <title>Some comments on the text</title>
82 Before proceeding to read the rest of this document, it should be
83 noted that the text assumes that certain files are placed in certain
84 directories. Where they have been specified, the conventions we adopt
85 here for locating these files are those of the relevant RFC (RFC-86.0,
86 see <link linkend="sag-see-also">bibliography"</link>). If you are
87 using a distribution of Linux (or some other operating system) that
88 supports PAM but chooses to distribute these files in a diferent way
89 you should be careful when copying examples directly from the text.
92 As an example of the above, where it is explicit, the text assumes
93 that PAM loadable object files (the
94 <emphasis remap='B'>modules</emphasis>) are to be located in
95 the following directory: <filename>/lib/security/</filename> or
96 <filename>/lib64/security</filename> depending on the architecture.
97 This is generally the location that seems to be compatible with the
98 Filesystem Hierarchy Standard (FHS). On Solaris, which has its own
99 licensed version of PAM, and some other implementations of UN*X,
100 these files can be found in <filename>/usr/lib/security</filename>.
101 Please be careful to perform the necessary transcription when using
102 the examples from the text.
106 <chapter id="sag-overview">
107 <title>Overview</title>
109 For the uninitiated, we begin by considering an example. We take an
110 application that grants some service to users;
111 <command>login</command> is one such program.
112 <command>Login</command> does two things, it first establishes that
113 the requesting user is whom they claim to be and second provides
114 them with the requested service: in the case of
115 <command>login</command> the service is a command shell
116 (bash, tcsh, zsh, etc.) running with the identity of the user.
119 Traditionally, the former step is achieved by the
120 <command>login</command> application prompting the user for a
121 password and then verifying that it agrees with that located on
122 the system; hence verifying that as far as the system is concerned
123 the user is who they claim to be. This is the task that is delegated
124 to <emphasis remap='B'>Linux-PAM</emphasis>.
127 From the perspective of the application programmer (in this case
128 the person that wrote the <command>login</command> application),
129 <emphasis remap='B'>Linux-PAM</emphasis> takes care of this
130 authentication task -- verifying the identity of the user.
133 The flexibility of <emphasis remap='B'>Linux-PAM</emphasis> is
134 that <emphasis>you</emphasis>, the system administrator, have
135 the freedom to stipulate which authentication scheme is to be
136 used. You have the freedom to set the scheme for any/all
137 PAM-aware applications on your Linux system. That is, you can
138 authenticate from anything as naive as
139 <emphasis>simple trust</emphasis> (<command>pam_permit</command>)
140 to something as paranoid as a combination of a retinal scan, a
141 voice print and a one-time password!
144 To illustrate the flexibility you face, consider the following
145 situation: a system administrator (parent) wishes to improve the
146 mathematical ability of her users (children). She can configure
147 their favorite ``Shoot 'em up game'' (PAM-aware of course) to
148 authenticate them with a request for the product of a couple of
149 random numbers less than 12. It is clear that if the game is any
150 good they will soon learn their
151 <emphasis>multiplication tables</emphasis>. As they mature, the
152 authentication can be upgraded to include (long) division!
155 <emphasis remap='B'>Linux-PAM</emphasis> deals with four
156 separate types of (management) task. These are:
157 <emphasis>authentication management</emphasis>;
158 <emphasis>account management</emphasis>;
159 <emphasis>session management</emphasis>; and
160 <emphasis>password management</emphasis>.
161 The association of the preferred management scheme with the behavior
162 of an application is made with entries in the relevant
163 <emphasis remap='B'>Linux-PAM</emphasis> configuration file.
164 The management functions are performed by <emphasis>modules</emphasis>
165 specified in the configuration file. The syntax for this
166 file is discussed in the section
167 <link linkend="sag-configuration">below</link>.
170 Here is a figure that describes the overall organization of
171 <emphasis remap='B'>Linux-PAM</emphasis>:
175 +----------------+ / +----------+ +================+
176 | authentication-[---->--\--] Linux- |--<--| PAM config file|
177 | + [----<--/--] PAM | |================|
178 |[conversation()][--+ \ | | | X auth .. a.so |
179 +----------------+ | / +-n--n-----+ | X auth .. b.so |
181 | service user | A | | |____,-----'
183 +----------------+ +------|-----|---------+ -----+------+
184 +---u-----u----+ | | |
185 | auth.... |--[ a ]--[ b ]--[ c ]
187 | acct.... |--[ b ]--[ d ]
189 | password |--[ b ]--[ c ]
191 | session |--[ e ]--[ c ]
194 By way of explanation, the left of the figure represents the
195 application; application X. Such an application interfaces with the
196 <emphasis remap='B'>Linux-PAM</emphasis> library and knows none of
197 the specifics of its configured authentication method. The
198 <emphasis remap='B'>Linux-PAM</emphasis> library (in the center)
199 consults the contents of the PAM configuration file and loads the
200 modules that are appropriate for application-X. These modules fall
201 into one of four management groups (lower-center) and are stacked in
202 the order they appear in the configuration file. These modules, when
203 called by <emphasis remap='B'>Linux-PAM</emphasis>, perform the
204 various authentication tasks for the application. Textual information,
205 required from/or offered to the user, can be exchanged through the
206 use of the application-supplied <emphasis>conversation</emphasis>
210 If a program is going to use PAM, then it has to have PAM
211 functions explicitly coded into the program. If you have
212 access to the source code you can add the appropriate PAM
213 functions. If you do not have accessto the source code, and
214 the binary does not have the PAM functions included, then
215 it is not possible to use PAM.
219 <chapter id="sag-configuration">
220 <title>The Linux-PAM configuration file</title>
221 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
222 href="../man/pam.conf-desc.xml"
223 xpointer='xpointer(//section[@id = "pam.conf-desc"]/*)' />
224 <section id='sag-configuration-file'>
225 <title>Configuration file syntax</title>
226 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
227 href="../man/pam.conf-syntax.xml"
228 xpointer='xpointer(//section[@id = "pam.conf-syntax"]/*)' />
230 <section id='sag-configuratin-dirctory'>
231 <title>Directory based configuration</title>
232 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
233 href="../man/pam.conf-dir.xml"
234 xpointer='xpointer(//section[@id = "pam.conf-dir"]/*)' />
236 <section id='sag-configuration-example'>
237 <title>Example configuration file entries</title>
239 In this section, we give some examples of entries that can
240 be present in the <emphasis remap='B'>Linux-PAM</emphasis>
241 configuration file. As a first attempt at configuring your
242 system you could do worse than to implement these.
245 If a system is to be considered secure, it had better have a
246 reasonably secure '<emphasis remap='B'>other</emphasis> entry.
247 The following is a paranoid setting (which is not a bad place
252 # default; deny access
254 other auth required pam_deny.so
255 other account required pam_deny.so
256 other password required pam_deny.so
257 other session required pam_deny.so
260 Whilst fundamentally a secure default, this is not very
261 sympathetic to a misconfigured system. For example, such
262 a system is vulnerable to locking everyone out should the
263 rest of the file become badly written.
266 The module <command>pam_deny</command> (documented in a
267 <link linkend="sag-pam_deny">later section</link>) is not very
268 sophisticated. For example, it logs no information when it
269 is invoked so unless the users of a system contact the
270 administrator when failing to execute a service application,
271 the administrator may go for a long while in ignorance of the
272 fact that his system is misconfigured.
275 The addition of the following line before those in the above
276 example would provide a suitable warning to the administrator.
280 # default; wake up! This application is not configured
282 other auth required pam_warn.so
283 other password required pam_warn.so
286 Having two '<command>other auth</command>' lines is an
290 On a system that uses the <filename>/etc/pam.d/</filename>
291 configuration, the corresponding default setup would be
292 achieved with the following file:
296 # default configuration: /etc/pam.d/other
298 auth required pam_warn.so
299 auth required pam_deny.so
300 account required pam_deny.so
301 password required pam_warn.so
302 password required pam_deny.so
303 session required pam_deny.so
306 This is the only explicit example we give for an
307 <filename>/etc/pam.d/</filename> file. In general, it
308 should be clear how to transpose the remaining examples
309 to this configuration scheme.
312 On a less sensitive computer, one on which the system
313 administrator wishes to remain ignorant of much of the
314 power of <emphasis remap='B'>Linux-PAM</emphasis>, the
315 following selection of lines (in
316 <filename>/etc/pam.d/other</filename>) is likely to
317 mimic the historically familiar Linux setup.
321 # default; standard UN*X access
323 auth required pam_unix.so
324 account required pam_unix.so
325 password required pam_unix.so
326 session required pam_unix.so
329 In general this will provide a starting place for most applications.
334 <chapter id='sag-security-issues'>
335 <title>Security issues</title>
336 <section id='sag-scurity-issues-wrong'>
337 <title>If something goes wrong</title>
339 <emphasis remap='B'>Linux-PAM</emphasis> has the potential
340 to seriously change the security of your system. You can
341 choose to have no security or absolute security (no access
342 permitted). In general, <emphasis remap='B'>Linux-PAM</emphasis>
343 errs towards the latter. Any number of configuration errors
344 can dissable access to your system partially, or completely.
347 The most dramatic problem that is likely to be encountered when
348 configuring <emphasis remap='B'>Linux-PAM</emphasis> is that of
349 <emphasis>deleting</emphasis> the configuration file(s):
350 <filename>/etc/pam.d/*</filename> and/or
351 <filename>/etc/pam.conf</filename>. This will lock you out of
355 To recover, your best bet is to restore the system from a
356 backup or boot the system into a rescue system and correct
360 <section id='sag-security-issues-other'>
361 <title>Avoid having a weak `other' configuration</title>
363 It is not a good thing to have a weak default
364 (<emphasis remap='B'>other</emphasis>) entry.
365 This service is the default configuration for all PAM aware
366 applications and if it is weak, your system is likely to be
367 vulnerable to attack.
370 Here is a sample "other" configuration file. The
371 <command>pam_deny</command> module will deny access and the
372 <command>pam_warn</command> module will send a syslog message
373 to <emphasis>auth.notice</emphasis>:
377 # The PAM configuration file for the `other' service
379 auth required pam_deny.so
380 auth required pam_warn.so
381 account required pam_deny.so
382 account required pam_warn.so
383 password required pam_deny.so
384 password required pam_warn.so
385 session required pam_deny.so
386 session required pam_warn.so
391 <chapter id='sag-module-reference'>
392 <title>A reference guide for available modules</title>
394 Here, we collect together the descriptions of the various modules
395 coming with Linux-PAM.
397 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
398 href="pam_access.xml"/>
399 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
400 href="pam_cracklib.xml"/>
401 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
402 href="pam_debug.xml"/>
403 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
404 href="pam_deny.xml"/>
405 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
406 href="pam_echo.xml"/>
407 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
409 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
410 href="pam_exec.xml"/>
411 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
412 href="pam_filter.xml"/>
413 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
415 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
416 href="pam_group.xml"/>
417 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
418 href="pam_issue.xml"/>
419 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
420 href="pam_keyinit.xml"/>
421 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
422 href="pam_lastlog.xml"/>
423 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
424 href="pam_limits.xml"/>
425 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
426 href="pam_listfile.xml"/>
427 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
428 href="pam_localuser.xml"/>
429 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
430 href="pam_loginuid.xml"/>
431 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
432 href="pam_mail.xml"/>
433 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
434 href="pam_mkhomedir.xml"/>
435 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
436 href="pam_motd.xml"/>
437 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
438 href="pam_namespace.xml"/>
439 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
440 href="pam_nologin.xml"/>
441 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
442 href="pam_permit.xml"/>
443 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
444 href="pam_rhosts.xml"/>
445 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
446 href="pam_rootok.xml"/>
447 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
448 href="pam_securetty.xml"/>
449 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
450 href="pam_selinux.xml"/>
451 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
452 href="pam_shells.xml"/>
453 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
454 href="pam_succeed_if.xml"/>
455 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
456 href="pam_tally.xml"/>
457 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
458 href="pam_time.xml"/>
459 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
460 href="pam_umask.xml"/>
461 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
462 href="pam_unix.xml"/>
463 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
464 href="pam_userdb.xml"/>
465 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
466 href="pam_warn.xml"/>
467 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
468 href="pam_wheel.xml"/>
469 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
470 href="pam_xauth.xml"/>
473 <chapter id="sag-see-also">
474 <title>See also</title>
478 The Linux-PAM Application Writers' Guide.
483 The Linux-PAM Module Writers' Guide.
488 The V. Samar and R. Schemers (SunSoft), ``UNIFIED LOGIN WITH
489 PLUGGABLE AUTHENTICATION MODULES'', Open Software Foundation
490 Request For Comments 86.0, October 1995.
496 <chapter id='sag-author'>
497 <title>Author/acknowledgments</title>
499 This document was written by Andrew G. Morgan (morgan@kernel.org)
500 with many contributions from
501 Chris Adams, Peter Allgeyer, Tim Baverstock, Tim Berger,
502 Craig S. Bell, Derrick J. Brashear, Ben Buxton, Seth Chaiklin,
503 Oliver Crow, Chris Dent, Marc Ewing, Cristian Gafton,
504 Emmanuel Galanos, Brad M. Garcia, Eric Hester, Michel D'Hooge,
505 Roger Hu, Eric Jacksch, Michael K. Johnson, David Kinchlea,
506 Olaf Kirch, Marcin Korzonek, Thorsten Kukuk, Stephen Langasek,
507 Nicolai Langfeldt, Elliot Lee, Luke Kenneth Casson Leighton,
508 Al Longyear, Ingo Luetkebohle, Marek Michalkiewicz,
509 Robert Milkowski, Aleph One, Martin Pool, Sean Reifschneider,
510 Jan Rekorajski, Erik Troan, Theodore Ts'o, Jeff Uphoff, Myles Uyema,
511 Savochkin Andrey Vladimirovich, Ronald Wahl, David Wood, John Wilmes,
512 Joseph S. D. Yao and Alex O. Yuriev.
515 Thanks are also due to Sun Microsystems, especially to Vipin Samar and
516 Charlie Lai for their advice. At an early stage in the development of
517 <emphasis remap='B'>Linux-PAM</emphasis>, Sun graciously made the
518 documentation for their implementation of PAM available. This act
519 greatly accelerated the development of
520 <emphasis remap='B'>Linux-PAM</emphasis>.
524 <chapter id='sag-copyright'>
525 <title>Copyright information for this document</title>
527 Copyright (c) 2006 Thorsten Kukuk <kukuk@thkukuk.de>
528 Copyright (c) 1996-2002 Andrew G. Morgan <morgan@kernel.org>
531 Redistribution and use in source and binary forms, with or without
532 modification, are permitted provided that the following conditions are
536 1. Redistributions of source code must retain the above copyright
537 notice, and the entire permission notice in its entirety,
538 including the disclaimer of warranties.
540 2. Redistributions in binary form must reproduce the above copyright
541 notice, this list of conditions and the following disclaimer in the
542 documentation and/or other materials provided with the distribution.
544 3. The name of the author may not be used to endorse or promote
545 products derived from this software without specific prior
549 Alternatively, this product may be distributed under the terms of
550 the GNU General Public License (GPL), in which case the provisions
551 of the GNU GPL are required instead of the above restrictions.
552 (This clause is necessary due to a potential bad interaction between
553 the GNU GPL and the restrictions contained in a BSD-style copyright.)
556 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
557 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
558 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
559 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
560 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
561 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
562 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
563 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
564 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
565 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH