Typo
[linux_from_scratch_hints.git] / OLD / pam+shadow+cracklib.txt
blob53cfb10026af67b548f16637d01074b2a23fb517
1 TITLE:          Linux-PAM + CrackLib + Shadow
2 LFS VERSION:    3.2+
3 AUTHOR:         Ted Riley <reesonline@messages.to>
5 SYNOPSIS:
6         How to configure cracklib, Linux-PAM and the Shadow suite
8 HINT:
10 CONTENTS
11 ========
12          1. Introduction
13          2. Changelog
14          3. Resources
15          4. CrackLib
16          5. Linux-PAM
17          6. Shadow
18          7. PAM Configuration
19          8. Trouble
20          9. Other Programs
21         10. Closing
24 INTRODUCTION
25 ============
26 We're going to install cracklib, Linux-PAM and the shadow package, in
27 that order.  (Shadow requires the PAM libraries, which require the
28 cracklib libraries.)  This hint can be used if you already have an LFS
29 installation in place or if you are installing LFS for the first time.
30 Once the binaries are in place, we will create and/or modify the
31 necessary configuration files to get everything up and running smoothly.
32 Please note:  Do not log out until all the configuration files have been
33 created, since you will not be able to log back in.  In fact, the safest
34 thing to do is test your configurations in a separate virtual terminal
35 before ending your session.
38 CHANGELOG
39 =========
40 Current Version
41 1.2 - 2002.06.10
42         Modified hint to work "in-line" with LFS installation
43         Replaced shadow patch with make flags
44         Replaced cracklib 'sed' command with make flags
46 1.1 - 2002.05.31
47         Corrected directories in shadow patch
48         Added troubleshooting section
49         Added other programs section
50         Added /usr/share/dict/words symbolic link and explained
52 1.0 - 2002.05.07
53         Updated explanation of shadow/PAM incompatibility
54         Cosmetic/grammatical changes
56 0.9 - 2002.04.28
57         Original draft
60 RESOURCES
61 =========
62 You will need the following packages:
64 cracklib (2.7 as of this hint):
65    http://www.users.dircon.co.uk/~crypto/download/cracklib,2.7.tgz
66 NOTE: That is not a typo; that is a comma.
68 a dictionary:
69    http://www.cotse.com/wordlists/allwords
70 NOTE: This website also has a dictionary called 'cracklib' but it is
71 15.6MB compared to 'allwords' which is 467KB.  I have had cracklib
72 seg fault with the larger dictionary, but not with the smaller.  I know
73 others (with better systems than mine) who have used the 'cracklib'
74 dictionary successfully.  Your mileage may vary.
76 Linux-PAM (0.75 as of this hint):
77    http://wwww.kernel.org/pub/linux/libs/pam/pre/library/Linux-PAM-0.75.tar.gz
78 NOTE: There is a cracklib-files.tgz here.  DO NOT USE IT.  This version
79 of cracklib appears to be 2.5.1, which has a known vulnerability
80 (see http://www.cert.org/vendor_bulletins/VB-97.16.CrackLib)
82 Shadow (4.0.3 as of this hint):
83    ftp://ftp.pld.org.pl/software/shadow/shadow-4.0.3.tar.gz
84 NOTE: There is no note for this one; insert humor attempt here.
87 CRACKLIB
88 ========
89 The following assumes that you downloaded the 'allwords' dictionary.
90 If you chose a different one, you will have to change the commands
91 below to match.
93 From the directory where you downloaded the dictionary:
94         
95 cp allwords /usr/share/dict/ &&
96 cd /usr/share/dict &&
97 ln -s allwords words
99 One note about the above commands:  Traditionally, the /usr/share/dict
100 directory had only one file: words.  The FHS standard does not prohibit
101 other files from being here as long as they are wordlists as well.  I
102 like to remember what dictionary I used, which is why I do not simply
103 rename 'allwords' to 'words.'  Creating the link to 'words' helps other
104 programs which might look in the standard location for a dictionary
105 (that is, the '/usr/share/dict/words' file).
107 Next, in the cracklib directory, we need to create a couple files:
108         
109 cat >> crack.h << "EOF"
110 #ifndef CRACKLIB_H
111 #define CRACKLIB_H
112 /* Pass this function a password (pw) and a path to the
113  * dictionaries (/usr/lib/cracklib_dict should be specified)
114  * and it will either return a NULL string, meaning that the
115  * password is good, or a pointer to a string that explains the
116  * problem with the password.
117  * You must link with -lcrack
118  */
119 extern char *FascistCheck(char *pw, char *dictpath);
120 #endif
123 cat >> util/create_cracklib_dict << "EOF"
124 #!/bin/sh
125 if [ -z "$*" ]; then
126         echo "Usage:"
127         echo "  $0 wordlist ..."
128         echo
129         echo "This script takes one or more word list files as arguments"
130         echo "and converts them into cracklib dictionaries for use"
131         echo "by password checking programs. The results are placed in"
132         echo "/usr/lib/cracklib_dict.*"
133         echo
134         echo "Example:"
135         echo "$0 /usr/share/dict/words"
136 else
137         /usr/sbin/mkdict $* | /usr/sbin/packer /usr/lib/cracklib_dict
141 And finally we compile cracklib from the source directory:
143 make DICTPATH=/usr/lib/cracklib_dict SRCDICTS=/usr/share/dict/words install &&
144 cp cracklib/libcrack.a /usr/lib &&
145 cp crack.h /usr/include &&
146 cp util/{mkdict,packer,create_cracklib_dict} /usr/sbin
148 Command Explanations:
150 cat >> crack.h ... : These commands create a header file for programs
151         to use when compiling with the crack library.
152 cat >> util/create_cracklib_dict ... : These commands create a script
153         which takes a wordlist as an argument and creates a new cracklib
154         dictionary.
155 make ... install : Makes the cracklib libraries with the correct
156         dictionary locations
157 cp cracklib.a /usr/lib : The make install command does not install the
158         static cracklib library, so we do it here.
159 cp crack.h /usr/include : This command copies the header file we created.
160 cp util/mkdict util/packer util/create_cracklib_dict : This command
161         copies the scripts and binaries needed to create new cracklib
162         dictionaries.
164 Please note:  The crack.h and create_cracklib_dict scripts were based
165 on those found in the cracklib.tgz archive.  Credit goes to the authors
166 of the originals, although they were unlisted (unless the author was
167 Alec Muffett, who wrote the cracklib library, in which case credit goes
168 to him). 
171 LINUX-PAM
172 =========
173 Now we will compile PAM:
175 ./configure --enable-static-libpam --with-mailspool=/var/mail \
176         --enable-suplementedir=/usr/lib &&
177 make &&
178 make install &&
179 cd /lib &&
180 for name in libpam libpamc libpam_misc; do
181         ln -s ${name}.so.0.75 ${name}.so.0
182         done
184 Command Explanations:
186 ./configure --enable-static-libpam : This builds static PAM libraries as
187         well as the dynamic libraries
188 --with-mailspool=/var/mail : This flag makes the mailspool directory
189         FHS-compliant
190 --with-suplementedir=/usr/lib : This flag installs the unix_chkpwd
191         binary in an FHS-compliant location
192 for name in libpam libpamc libpam_misc; do : The installer creates
193         broken symlinks.  These commands correct the library links.
195 If you don't have sgml tools on your computer, you will receive an error
196 message after the install.  To install the docs manually, run the
197 following commands from the Linux-PAM source directory:
199 cd doc
200 tar zxf Linux-PAM-0.75-docs.tar.gz
201 cp -a html /usr/share/doc/Linux-PAM/
202 cd /usr/share/doc
203 chown -R root:root Linux-PAM
204 touch Linux-PAM
205 cd Linux-PAM
206 touch *
208 (The final three commands aren't necessary unless you use a time-stamp
209 sensitive install manager like install-log.)
212 SHADOW
213 ======
214 There is an incompatibility between the current versions of Shadow and
215 the latest versions of Linux-PAM.  For the record, the maintainer of the
216 shadow package believes the incompatibility lies in the PAM libraries,
217 not in shadow.  Therefore, he advises using a different version of PAM.
218 (available from ftp://ftp.pld.org.pl/software/pam/).  However, I prefer
219 to use the latest versions of both packages; the compiler flags below
220 will accomplish this.
222 LDFLAGS="-lpam -lpam_misc" ./configure --prefix=/usr --enable-shared \
223         --with-libpam --without-libcrack &&
224 make &&
225 make install &&
226 cd /usr/sbin &&
227 ln -sf vipw vigr &&
228 rm /bin/vipw &&
229 mv /bin/sg /usr/bin &&
230 mv /lib/{libmisc.*a,libshadow.*a} /usr/lib &&
231 cd /usr/lib &&
232 ln -sf ../../lib/libshadow.so
233 sed 's%/var/spool/mail%/var/mail%' etc/login.defs.linux > /etc/login.defs
234 cp debian/securetty /etc/securetty
236 Command Explanations:
237 LDFLAGS="..." ./configure : The compiler flags allow the shadow package
238         to link correctly against the PAM libraries; they must be
239         entered on the same line as the configure command.
240 --enable-shared : Shadow no longer creates shared libraries by default,
241         so this flag is used.
242 --with-libpam : This flag compiles with PAM support.
243 --without-libcrack : Cracklib will be called through PAM, so we do not
244         need it here.
245 ln -sf vipw vigr ... ln -s ../../lib/libshadow.so : These commands fix
246         broken links and un-installed libraries.  They are also useful for
247         refreshing the time-stamps on the files if you use a time-stamp
248         sensitive installer (like install-log).
249 sed ... login.defs : This will create the /etc/login.defs file (if you
250         don't already have one) and will make the mail directory
251         FHS-compliant.
252 cp debian/securetty /etc/securetty : This will create the securetty file
253         which prevents root logons from all but listed terminals.
255 Please note:  We no longer need the 'limits' and 'login.access' files in
256 /etc since PAM will handle these functions.  You may safely delete these
257 files if you had previously created them.
260 PAM CONFIGURATION
261 =================
262 We are almost done.  Now we will customize our setup.  Please note that
263 the PAM configuration files below are necessary for PAM to function.
264 Without these files, you will not be able to log in.
266 You can comment out the following entries in login.defs since PAM is now
267 handling them.  In the right column are the PAM modules which replace
268 the entries:
270 DIALUPS_CHECK_ENAB      (not sure - anyone know?)
271 LASTLOG_ENAB            (pam_lastlog.so)
272 MAIL_CHECK_ENAB         (pam_mail.so)
273 OBSCURE_CHECKS_ENAB     (pam_cracklib.so)
274 PORTTIME_CHECKS_ENAB    (pam_time.so)
275 CONSOLE                 (pam_securetty.so)
276 MOTD_FILE               (pam_motd.so)
277 NOLOGINS_FILE           (pam_nologin.so)
278 PASS_MIN_LEN            (pam_cracklib.so)
279 SU_WHEEL_ONLY           (pam_wheel.so)
280 CRACKLIB_DICTPATH       (pam_cracklib.so)
281 PASS_CHANGE_TRIES       (pam_cracklib.so)
282 PASS_ALWAYS_WARN        (pam_cracklib.so)
283 MD5_CRYPT_ENAB          (pam_unix.so with md5 flag)
284 CONSOLE_GROUPS          (pam_groups.so)
285 ENVIRON_FILE            (pam_env.so)
287 Several people have noticed a small problem with pam_issue.so.
288 Specifically, if you enter the correct password the first time, the login
289 fails, even if pam_issue is set to optional.  However, if the wrong password
290 is entered at least once, the correct password will work for any further
291 attempts. I think this is because the first issue file is displayed by agetty,
292 not login.  All the other issue messages are displayed by login.  So, if you
293 succeed the first time, pam_issue is not called.  I'm not sure how to get
294 around this problem (since even the optional setting doesn't work), so I
295 have left the issue command in /etc/login.defs and taken it out of PAM. If
296 anyone knows how to fix this, please let me know.
298 If you want to use the access or limits modules (among others), you can edit
299 the configuration files in /etc/security/.  Currently, my files are still
300 fully commented out (the default), so I'm not much help for suggestions
301 on those.  If anyone is using these files, I would love to hear from
302 them, though.
304 Below are my pam.d files.  I prefer separate files under pam.d as
305 opposed to one file (/etc/pam.conf), but use whichever you prefer.
306 In fact, if you want to, you can use both by specifying the
307 --enable-both-confs flag when compiling Linux-PAM.
309 /etc/pam.d/login:
310 # Begin /etc/pam.d/login
311 auth    requisite       pam_securetty.so
312 auth    requisite       pam_nologin.so
313 auth    required        pam_env.so
314 auth    required        pam_unix.so
315 account required        pam_access.so
316 account required        pam_unix.so
317 session required        pam_motd.so
318 session required        pam_limits.so
319 session optional        pam_mail.so     dir=/var/mail standard
320 session optional        pam_lastlog.so
321 session required        pam_unix.so
322 # End /etc/pam.d/login
324 /etc/pam.d/other:
325 # Begin /etc/pam.d/other
326 auth            required        pam_deny.so
327 auth            required        pam_warn.so
328 account         required        pam_deny.so
329 session         required        pam_deny.so
330 password        required        pam_deny.so
331 password        required        pam_warn.so
332 # End /etc/pam.d/other
334 /etc/pam.d/passwd:
335 # Begin /etc/pam.d/passwd
336 password        required        pam_cracklib.so \
337     retry=3 difok=8 minlen=15 dcredit=3 ocredit=3 ucredit=2 lcredit=2
338 password        required        pam_unix.so     md5 shadow use_authtok
339 # End /etc/pam.d/passwd
341 /etc/pam.d/shadow:
342 # Begin /etc/pam.d/shadow
343 auth            sufficient      pam_rootok.so
344 auth            required        pam_unix.so
345 account         required        pam_unix.so
346 session         required        pam_unix.so
347 password        required        pam_permit.so
348 # End /etc/pam.d/shadow
350 /etc/pam.d/su:
351 # Begin /etc/pam.d/su
352 auth    sufficient      pam_rootok.so
353 auth    required        pam_unix.so
354 account required        pam_unix.so
355 session required        pam_unix.so
356 # End /etc/pam.d/su
358 /etc/pam.d/useradd:
359 # Begin /etc/pam.d/useradd
360 auth            sufficient      pam_rootok.so
361 auth            required        pam_unix.so
362 account         required        pam_unix.so
363 session         required        pam_unix.so
364 password        required        pam_permit.so
365 # End /etc/pam.d/useradd
367 One final note:  The shadow file (and useradd, for that matter) require
368 a password field, or else they will return a 'PAM chauthtok failed'
369 error.  Also, the shadow file affects many of the other programs in the
370 shadow suite (chfn, chage, groupdel, userdel, etc.).  These programs
371 interface with PAM as 'shadow' instead of their own program name.
374 TROUBLE
375 =======
376 Here are a couple problems that crept up while I was installing the above
377 programs myself.  Just in case you run in these problems yourself, here
378 are some tips to help you resolve them.  Of course, you will not need
379 these because everything will work great the first time. ;-)
381 Cracklib Seg Fault:
382 With a large dictionary file, cracklib gave a segmentation fault the
383 second time I tried to change a password.  (The first time worked.)
384 To fix this, I ran the script create_cracklib_dict, as listed below (I
385 was using the 'cracklib' dictionary at the time):
387 create_cracklib_dict /usr/share/dict/cracklib
389 This command rebuilt the cracklib dictionary files and cracklib worked
390 fine the next time I changed a password.  Then it crashed again the
391 following time.  However, when I ran the above command with the 
392 'allwords' dictionary listed above, cracklib worked and has worked since. 
394 As noted above, this error may be a result of my computer's limited RAM
395 and swap space.  Other people have stated that the cracklib dictionary
396 has worked fine for them.
398 Incorrect Root Password:
399 Later, due to a misconfiguration, I found myself unable to log in as root.
400 To fix this, I used a boot disk (the Slackware boot disk, to be exact)
401 which allowed me to log in as root without a password.  Once I was
402 logged in, I mounted my LFS system.  Then, I renamed the pam.d directory
403 and created a new pam.d directory with only the 'other' file.  This
404 temporary file is listed below:
406 # Begin temporary /etc/pam.d/other
407 auth            required        pam_unix.so     nullok
408 account         required        pam_unix.so
409 session         required        pam_unix.so
410 password        required        pam.unix.so     nullok
411 # End temporary /etc/pam.d/other
413 I also edited my /etc/passwd file (after making a backup, of course) and
414 removed the password field for root.  After rebooting, I was able to log
415 in as root without a password.  Then, I copied my original pam.d directory
416 back in place and changed the root password, testing the configuration
417 in another virtual terminal.
420 OTHER PROGRAMS
421 ==============
423 The main reason to install PAM (at least for me) was so that different
424 programs could use it.  Below are a few programs that utilize PAM, as
425 well as instructions how to compile PAM support into them.
427 SSH:
428 OpenSSH (from http://www.openssh.com/) has a compile option for PAM.
429 Simply specify the --with-pam flag when you run the configure script.
430 The PAM configuration file I use for ssh is almost identical to the one
431 used for login, with one exception: the securetty line is removed (so we
432 can log in through ssh from anywhere).  For simplicity's sake, the file
433 is listed below:
435 /etc/pam.d/sshd:
436 # Begin /etc/pam.d/sshd
437 auth    requisite       pam_nologin.so
438 auth    required        pam_env.so
439 auth    required        pam_unix.so
440 account required        pam_access.so
441 account required        pam_unix.so
442 session required        pam_motd.so
443 session required        pam_limits.so
444 session optional        pam_mail.so     dir=/var/mail standard
445 session optional        pam_lastlog.so
446 session required        pam_unix.so
447 # End /etc/pam.d/sshd
449 PPPD:
450 Another program that is useful if you use a modem (including DSL) is
451 the pppd program (available from http://www.samba.org/ppp/).  To enable
452 PAM in pppd, simple add the USE_PAM=y flag after the make command. 
453 My configuration file for ppp is sparce compared to sshd and login,
454 simply because I do not use ppp except to dial out.  The configuration
455 file for pppd is listed below:
457 /etc/pam.d/ppp:
458 # Begin /etc/pam.d/ppp
459 auth    requisite       pam_nologon.so
460 auth    required        pam_unix.so
461 account required        pam_unix.so
462 session required        pam_unix.so
463 # End /etc/pam.d/ppp
465 Please note that the file is called ppp, not pppd.  This is because the
466 ppp daemon uses "ppp" to interface with PAM instead of "pppd."
469 CLOSING
470 =======
471 Many thanks to Yannick Tousignant for writing the previous pam hint and
472 helping me get my foot in the door.  And of course, thanks to Gerard
473 Beekmans and the rest of the LFS crew.  
475 Also, thanks to the following individuals for their contributions:
476 Thien Vu
477 Adrian Woffenden
479 If you need additional help, be sure to check out the Linux-PAM manuals
480 at http://www.kernel.org/pub/linux/libs/pam/Linux-PAM-html/
481 Also, help may be available on the Shadow mailing list at
482 http://lists.pld.org.pl/archive/index.htm?10
484 Enjoy.