User Authentication HOWTO Peter Hernberg / ?? 2000/05/02 ? Linux ? ? ?? ?? ? ? ? ?? ? ? (PAM) ? ??? ? ? ?? ? ?? ? ----------------------------------------------------------------------- Table of Contents 1. ? 1.1. ? ? 1.2. ? ?? 1.3. ? ??? 1.4. ? 1.5. ? ? ? 1.6. ? 1.7. ? 2. ?? ? ? ? ? 2.1. /etc/passwd ?? 2.2. ? ? 2.3. /etc/group /etc/gshadow 2.4. MD5 ??? ? ? 2.5. ? 3. PAM (Pluggable Authentication Modules) 3.1. ? PAM ?? 3.2. PAM ?? 3.3. PAM 3.4. ? ? 4. ?? ? ? ?? ? 4.1. /etc/pam.d/other ? 4.2. ? ? ?? ? ?? 4.3. ? ? 4.4. ? ? ? ?? 4.5. ? ? ? MD5 ? ? 5. 5.1. Apache + mod_auth_pam 5.2. 5.3. mod_auth_pam ? ?? 5.4. PAM 5.5. Apache 5.6. ?? 6. ? 6.1. PAM 6.2. ? 6.3. ??? 7. 7.1. ? 1. ? 1.1. ? ? ?? ? ??? ? ? ( ?? ? ) ???? ? ? ?? ? ? ?? ? ? ? ? ???? ? ?? ?? ? Linux ? ? ?? ?? HOWTO ? ? ? ?? ?? ? ? ? ???? ?? ? ??? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ?? ? ----------------------------------------------------------------------- 1.2. ? ?? ?? ??? ? ?? ? ? ? ? ?? http://www.linuxdoc.org ? ----------------------------------------------------------------------- 1.3. ? ??? ? ? ? UFO ? ?? ? ? ? petehern@yahoo.com ----------------------------------------------------------------------- 1.4. ? v0.1 (May 13, 2000) ? ? ( ??) v0.3 (May 14, 2000) ( ??) v0.5 (May 15, 2000) ??? ? ? ?? ? ???? ? ? ( ??) v0.7 (May 15, 2000) : ----------------------------------------------------------------------- 1.5. ? ? ? (c) 2000 Peter Hernberg ????? ? ? ? ??? ? ? ? ?? ? ? ? * ? ?? ?? ?? ? ? ? ?? ? ? ? ? ?? ? * ? ? ?? ? ? ?? ? * ? ?? ? ? ? ?? ??? ? * ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ??? ?? ? ?? ?? ? ?? ????? ? ? ?? ?? ? ? ??? ? ? ? ??? ?? (? ? ? SGML ) GNU General Public License ? ?? ? ?? GNU ? ? FTP ? ? ? ----------------------------------------------------------------------- 1.6. ? ?? ? ? 18 ? ? ? ? ? ? ? ?? Debian ? ? ? ?? ?? ?? ?? CGR ? ? ? Sandy Harris ? ? ? ? ? ? ? ?? ? ? ? ? ? ?? ? ? ? ? ----------------------------------------------------------------------- 1.7. ? ? ?? ? ?? ? ?? ? ? ? ? ? ?? ?? ? ? ? ----------------------------------------------------------------------- 2. ?? ? ? ? ? 2.1. /etc/passwd ?? ?? ? Linux ? ? ?? ( *nix ? ) ?? ?? /etc/passwd ? ?? ?? ?? ? ?? ? ??? ?? ? ? ? ??? ID (uid ??? ? ) ?? ID (gid ??? ) ? ?? ( ?? ? ? ? ) ? ?? ?? ? ?? ??? ? ? / etc/passwd ? ? ? ? ? ??? ? ? pete:K3xcO1Qnx8LFN:1000:1000:Peter Hernberg,,,1-800-FOOBAR:/home/pete:/bin/bash ?? ??? ? ???? ? ? ? ? ??? ? 6 ??? ?? ? ? ? ? ? ?? ?? ? ?? ? ?? ?? ??? ? ?? ?? ??? HOWTO ? ? ? ?? ----------------------------------------------------------------------- 2.2. ? ? ? ? /etc/passwd ? ???? ??? ???? ? ?? pete:x:1000:1000:Peter Hernberg,,,1-800-FOOBAR:/home/pete:/bin/bash ?? ?? ??? ?? ? ? ??? ??? ?? ?? ?? ? ??? ? ? ?? ? ? /etc/passwd ? ? ?? ? ???? ?? ? ? ? ?? ? ?? ????? ? ? ??? ? ??? ? ??? ?? ? ? ? ? ??? ? ? ?? ? ????? ? ? ? ? ?? ? ?? ?? ?? ? ? ?? ?? ? ? ? ? ? ? ? ? ? /etc/passwd ? ? ? ? ? ? x ? ???? ?? ?? ? ? ? /etc/shadow ? ? ? /etc/shadow ??? ??? ?? ? ?? ?? ? ?? ?? ??? ? /etc/shadow ?? ? ? ?? ? ? ??? ?? ? ? ? ?? ? ? ??? ?? ? ? ?? ? ? ? ? ? ? ? ??? ? ? pete:/3GJllg1o4152:11009:0:99999:7::: ----------------------------------------------------------------------- 2.3. /etc/group /etc/gshadow ?? ? /etc/group ? ? /etc/passwd ?? ? ? ?? ?? ? ? ? ? id (gid) ? ? ?? ? ? ?? ?? ? /etc/group ? ? ?? ??? ? ? pasta:x:103:spagetti,fettucini,linguine,vermicelli ? ? ?? "x" ?? ? ?? ? ?? ?? ? ?? ? ? ?? ? ?? ? ?? ? ? ? ???? ? ?? ?? ?? ?? ? ?? /etc/gshadow ? ? ? ? ? ----------------------------------------------------------------------- 2.4. MD5 ??? ? ? ? ?? Unix ?? ? ? crypt() ? ? ? ( crypt() ? ???? ?? crypt(3) ????? ? ) ?? ? ? ??? ?? ??? ?? ? ? ? ?? ? ??? ? ??? ?? ? ? ? ?? ? ? ? ?? ?? ? ?? ? ? ? ?? ?? MD5 ?? ?? ?? ? ? ? ?? ?? ? ? ? ?? ???? ? ( MD5 ?? ?? ?? ? ? ??? RFC1321 ? ) MD5 ? ? ??? ? ? ?? ? ? ??? ? ? ? ?? ??? ? ?? ??? ? ----------------------------------------------------------------------- 2.5. ? ? ? ?? ? ?? ? ?? ? ? ? ? ? (MD5 ???? ? ? ? ? MD5 ???? /etc/passwd ??? ) ? login su ???? ? ?? ?? ? ? ? ?? ? ?? ? ? ? ? ? ?? ?? ?? ?? ?? ? ? ? ? ?? ? ? ? ?? ? ? ? ?? PAM ? ----------------------------------------------------------------------- 3. PAM (Pluggable Authentication Modules) PAM (Pluggable Authentication Modules) ? ? ? ?? ? ? ????? ?? ----------------------------------------------------------------------- 3.1. ? PAM ?? ? Linux ? su passwd login ?? xlock ? ? ? ?? ? ? ? /etc/passwd ??? ? ? ?? ? ? ? ? ? ???/etc/passwd ? ? ? ? ??? ?? ? ??? ? ?? ???? ?? MD5 ? ? ? ? ? ?? ? ? ? ? ? ? ? ?? ??? ? ? ?? ? ? ? ? ?? ? ??? ? ? PAM ? ?? ? ? ? ? ?? ? ? ? ?? ?? ? ? ?? ----------------------------------------------------------------------- 3.2. PAM ?? Linux-PAM System Administrator's Guide Linux-PAM ? ? ? ?? ? ?? ? ? ?? ?? ? ? ?? ? ? ?? ?? ? ? ?? ? ? ?? ? ? ????? ? ? ? ?? ?? ? ???PAM ? ? ? /etc/passwd ? ?? ? ? ?? ? ? ? ?? ? ? ?? ? ? ? ? ? PAM ? ? ? ? ? ??? ? ? ? ? ?? ? ? ?? ?? ? PAM ? ? ????? PAM ? ??? ? ? ??? ? ? ??? ? ? ? ? ?? ? ? ?? ? ???? ? ? ? ? ? ?? ? ? ?? ?? PAM ?? ?? ?? ?? ? ? ? ? ? ----------------------------------------------------------------------- 3.2.1. PAM ?? ? ? ?? ? ? ? ? ? ?? PAM ?? ? ?? ? ? ? PAM ?? ? ? ? ?? ? * Redhat ? 5.0 ? * Mandrake 5.2 ? * Debian ? 2.1 ? ( 2.1 ? ? ? ? 2.2 ? ? ) * Caldera ? 1.3 ? * Turbolinux ? 3.6 ? * SuSE ? 6.2 ? * ( ) Vine ???? * ( ) Kondara ???? ?? ? ?? ?? ? ??? ?? ?? ?? ??? ?? ? ?? ? petehern@yahoo.com ----------------------------------------------------------------------- 3.2.2. PAM ? ?? PAM ? ?? ?? ?? ?? ?? ?? ?? ? HOWTO ?? ? PAM ?? ?? ? ??? ?? ?? ? ? ? ? ?? ? ?? ? ?? ?? ?? ?? ? ? ? ?? ?? ? ??? ? ???? ?? ? ??? ? ?? PAM ?? ?? ?? ? ? ? ----------------------------------------------------------------------- 3.3. PAM ?? ?? ?? ? ? ??? ? ?? ----------------------------------------------------------------------- 3.3.1. PAM PAM /etc/pam.d ? ( ? /etc/pam.d ? ? ?? ?? ? ? ??? ? ?? ?? ? ) ?? ?? ? ??? ??? ?? ~$ cd /etc/pam.d /etc/pam.d/$ ls chfn chsh login other passwd su xlock /etc/pam.d/$ ? ??? ?? ? ?? ? ? ?? ?? ? ? ?? ? ????? ? ?? ? ??? ??? ??????? ??? ? ?? ? ? ? ? ? ? ??? PAM ? ? ? ?? ?? ?? ? ? ? ( other ? ? ) ?? ? ?? PAM ??? ?? ( ?? ? ?? ? ?? ? ) /etc/pam.d/$ cat login # PAM ? ( login ? ) auth requisite pam_securetty.so auth required pam_nologin.so auth required pam_env.so auth required pam_unix.so nulok account required pam_unix.so session required pam_unix.so session optional pam_lastlog.so password required pam_unix.so nullok obscure min=4 max=8 ?? ?? ? ? ? ----------------------------------------------------------------------- 3.3.2. ? ? ? ? ?? ? ?? ? /etc/pam.d ? ?? ? ? ? ? ?? ? ? ? ? PAM ??? ? ? ?? ?? ? PAM ? ? ? ? ? ? ? ?? ??? ?? ? ?? PAM ?? ? /etc/pam.d ? ? ? PAM ? /etc/pam.conf ? ? ? ? ?? ? PAM ?? ??? ? ? ? ? ? PAM ? ?? ? ?? ? ?? ? ?? Section 3.3.4 pam.conf ? ? ? ----------------------------------------------------------------------- 3.3.3. ? ? PAM ? ??? ? ? ???? ? type control module-path module-arguments login ? ( ??? ??? ) ? ?? ? PAM ? ? ???? ?? PAM type type ? ?? ???? ?? ? ? ?? ? PAM ??? ? ? ??? ?? ?? ? ? ?? ?? ? ? ?? ? ? PAM ? 4 ?? ? account ?? ? ?? ? ?? ? ? ? ? ??? ? ?? ( ? ? ?? ? ) ? auth ?? ? ? ? ??? ? ? ? ? ? ? ? (biometrics) ??? ? ?? ?? ?? ? password ?? ? ? ? ? ? ? ? ? ? ? ?? session ?? ? ??? ?? ? ??? ? ? ?? ? ?? ? ? ?? ? ? ?? ? ?? ? ? ? ?? ? ?? ?? ? ?? ?? login ? type ?? ? ??? ? ? ? ? ? login ? ? ? ?? ? ? ? ??? ? ?? ?????? ? ?? ? ? ? ? control control ? ? ? ? ? ?? PAM ?? ?? PAM ? ? 4 ? control ? requisite ?? ?? ?? ? ? ? ? ? required ? ?? ? ? ? ? PAM ? ? ? ? ??? ? ? ? ? ? ? ?? ??(? type ) ??? ?? ?? ? sufficient ?? ?? ? ? ? required ?? ?? ??? ?? ? ? ??PAM ? ??? ? ( ?? "sufficient" ? ? "sufficient" ? ? "required" ? ?? ?? ? ? ? ? ?? ? ? ? ? Linux-PAM System Administrators' Guide (http://www.kernel.org/ pub/linux/libs/pam/Linux-PAM-html/sag-configuration.html) ? ???? ? ? ? ? ? ? ? ) optional ?? ?? ??? ? ?? ? ??? ? ? ?? ? ??(? ? ? )? ? ?? ?? ? ? login ? ? ?? control ?? ???? ? ? ? required ?? ?? pam_unix.so ( ? ? ?? ?? ) ? ? ??? requisite ?? ?? ?? pam_securetty.so ( ?? ? ? ?? ?? ? ) ? ? ??? optional ?? ?? ?? pam_lastlog.so ( ? ? ??? ? ? ? ?? ) ???? ? ( : control ?? ?? ? ?? ? ??? The Linux-PAM System Administrators' Guide ? ) module-path module-path ? ??? ?? ? ?? ( ? ? ) ?? ? ? ?? PAM ?? ?? login ? ? ? ?? ?? ?? ? ? PAM ? PAM ??? ? ?? ?? /usr/lib/security/ ? ? ??? ? ?? Linux ? ?? ? ? ? ?? ? ??PAM ? ?? /lib/security ? ?? ? ?? module-arguments module-arguments ? ? ?? ?? ?? ? ?? ?? ? ?? ?? ? ? login "nullok" ("null ok" ? ? ) ? ? pam_unix.so ? ?? ? ? ? ? ?? ? ? (null)? ? ? ?? ----------------------------------------------------------------------- 3.3.4. pam.conf ? ? PAM ? /etc/pam.d/ ? ?? ? ?? /etc/pam.conf ? ? ?? PAM ???? ??? ?? ? ? ???? ? ? /etc/pam.conf ? ?? ?? ? ? ?? ? ? ? /etc/pam.d/login ? ??? auth required pam_unix.so /etc/pam.conf ? ? ? ??? ?? ? ?? login auth required pam_unix.so ?? ? ? ?? ? ? ? PAM ? ? ?? ?? ? ----------------------------------------------------------------------- 3.4. ? ? PAM PAM ? ?? ?? ??? ?? ? Linux-PAM System Administrator's Guide ??? ? ? ?? PAM ? ?? ?? ? ?? ? ? ??? ----------------------------------------------------------------------- 4. ?? ? ? ?? ? ? ?? ? ?? ?? ?? ? ??? ? ? ? ? ? ???? ? ???? ? ???? ? ? ? ? ? ? ?? ? ? ? ? ??? ? ??? ?????? ?? ? ----------------------------------------------------------------------- 4.1. /etc/pam.d/other ? /etc/pam.d ? ? ? ?? ?? ? ??? ? ? /etc/pam.d/other ? ?? ? ? ? ? ? ( ?? ? ? ) xyz ? ? ?? ? ???? ? PAM /etc/pam.d/xyz ? ? ? ? ?? ? ? ? ? / etc/pam.d/other ? ??? /etc/pam.d/other ? PAM ? ?? ??? ? ? ? ?? ? ? /etc/pam.d/other ? ?? ???? ???? ?? ? ? ? ? ?? ? ? ? ? ----------------------------------------------------------------------- 4.1.1. /etc/pam.d/other ? ? ? ??? ?? ? auth required pam_deny.so auth required pam_warn.so account required pam_deny.so account required pam_warn.so password required pam_deny.so password required pam_warn.so session required pam_deny.so session required pam_warn.so ?? ? ? ? ? ? 4 ?? ? ?? ? ?PAM (pam_deny.so ? ?? ?? )? ? (pam_warn.so ? ?? ?? ) ? ?? ? ? PAM ??? ?? ? ?? ? ? ? ? ? ? ?? ?? ? ? ?? /etc/pam.d/login ? ? ? ? ? ? ? ? ??? ? ? ----------------------------------------------------------------------- 4.1.2. ? ? ? ? ?? ? ? auth required pam_unix.so auth required pam_warn.so account required pam_unix.so account required pam_warn.so password required pam_deny.so password required pam_warn.so session required pam_unix.so session required pam_warn.so ? ? ? ? ? (pam_unix.so ? ?? ?? )? ? ? ?? ? ? ? ? ?? ?? ? ? ????? ? ? ? ???? ? ? ? ? ?? ? ? ----------------------------------------------------------------------- 4.1.3. /etc/pam.d/other ? ? ??/etc/pam.d/other ? ?? ?? ?? ? ? ??? ? ? ?? ? ? ? ?? ? ? ?? ? ? ? ?? ? ?? PAM ? ? ? ----------------------------------------------------------------------- 4.2. ? ? ?? ? ?? ? Linux ? ? ftp webserver, mail ? ?? ?? ? ? ? ?? ? ? ???? ? ? ? ? ? ? ? ? ??? ? ???? ?? ? ??? ? ?? ? ? ? ?? ?? ? ?? ? ? ? ?? ? ?? (null) ? ? ? ? ??? ? ?? ?? ??? ? ? ?? ? ? ?? ? ? ? ? "nullok" ? ? ?? (module-argument) ? ? ?? ? ?? ?? "auth" ? ??? ?? ?? ?? ? ?? ? ? ? ?? ? ?? login ? ? ?? rlogin ssh ?? ? ? ? /etc/pam.d/login ? ??? auth required pam_unix.so nullok ? ??? ? ? ? auth required pam_unix.so ----------------------------------------------------------------------- 4.3. ? ? /etc/pam.d ? ? ?? ? ?? ? ? ?? ? ? ? ? ? ? ? ?? ?? ? ? ? ? ? ?? ? ??? ? ? ?? ? ? PAM ? ?? ? ?? ? ? ? ? ? ?? ?? ? ? ?? ? ? ?? ? ?? PAM /etc/pam.d/other ? ( ??) ? ? ? ? ? ? ? ?? ??? ? ? ? ? ? ?? ?? ? ? ----------------------------------------------------------------------- 4.4. ? ? ? ?? ? ? ? ?? ? ????? ? ? ? ? ? ? ?????? ? ? ? ?? ?? ? ?? ? ? ? ?? ? ? ? ?? ? ? ? ?? "crack" "John the Ripper" ? crack ? ?? ?? ?? ? ?? ? ? ? ?? John the Ripper ? http://www.false.com/security/john/index.html ? ? ? ? ?? ? ? ??? ? ?? ? ?? ? ? ? ? ?? ? ? ?? ? ? ? ? ?? ?? ? crack ??? ? ? ? PAM ?? ?? ?? ?? ?? ?? ?? ? ? ?? ? ?? ? ?? ? ? ?? ? ? ? ? ? ----------------------------------------------------------------------- 4.5. ? ? ? MD5 ? ? ?? ?? ?? ? ? ? ? MD5 ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ?? ?? ?? MD5 ? ? ???? ?? ?? ? ?? ???? ? ? ? ? ?? ? MD5 ? ? ? ?? ? ? ? ?? ? ? ?? ? ? ? ? ? Shadow Password HOWTO ( ) ----------------------------------------------------------------------- 5. ???? ? ?? ? ? ? ? ? ?? ? ----------------------------------------------------------------------- 5.1. Apache + mod_auth_pam ?? ? ? mod_auth_pam ? Apache ? ?? ?? ? PAM ?? ? ? ?? ? ? ? PAM ? ? Apache ?? ?? ?? ?? ?? ? ? ?? ? ??? ? Linux ? ? ?? ??? ? ? ----------------------------------------------------------------------- 5.2. ? ? ? ? ?? ? family ? ? ?? ? PAM ?? ? ?? ? ?? ?? ?? ?? ? family ? ? ??? ?? ?? ?? family ? ?? ? ? ? ?? ? ? ----------------------------------------------------------------------- 5.3. mod_auth_pam ? ?? ? mod_auth_pam http://blank.pages.de/pam/mod_auth_pam ? ? ? ? ? mod_auth_pam ? ?? ? ( root ? ??? ? ? ? ) ~# tar xzf mod_auth_pam.tar.gz ~# cd mod_auth_pam-1.0a ~/mod_auth_pam-1.0a# make ~/mod_auth_pam-1.0a# make install ? mod_auth_pam ??? ?? ? ?? ? ? ?? ? apache-dev ? ?? ??? ?? ? ?? ? ? mod_auth_pam ? ?? ?? ??Apache ? Apache ??? ? ? ?? ? ? ? ( ??root ?? ? ? ) ~# /etc/init.d/apache restart ----------------------------------------------------------------------- 5.4. PAM Apache ? PAM /etc/pam.d/httpd ?? ( mod_auth_pam ? ? ?? ? ? ?? ?? ? ) ? ?? pam_pwdb.so ? ? ?? ??? ? ?? ?? ? ? ? ? ( ? ? ? ? ? ??) ?? /etc/pam.d/httpd ? ? ??? ?? ? ? ?? ----------------------------------------------------------------------- 5.4.1. PAM Apache ? PAM ? ? PAM ? ??? ? ?? ? ? ? ? ?? PAM ? ? Unix ? ? ?? ? ? ? ???? ?? ? ? ? ?? ? ? ?? ? "auth " "pam_unix.so" ? ?? ? ? ? ? ? ? ? ? ?? ? ?? control "required" ? ?? ? ?? ? ? ? / etc/pam.d/httpd ? ? ? ? ??? ? ? auth required pam_unix.so ? ?? ? ? ??? ?? ? ? ? ( ??? ?? ?? ? ? ? ? ? ? ? ? ?? ) "account" ? ? ? ?? ? pam_unix.so ? ?? ? ? ?? ?? "control" ? " required" ? ? ?? ?? ? /etc/pam.d/httpd ? ??? ?? auth required pam_unix.so account required pam_unix.so ?? ? ? ? ??? ? PAM ? ? ? ?? ?? ? ? ? ----------------------------------------------------------------------- 5.5. Apache PAM Apache ? ? ? ?? ?? Apache PAM ? ? family ? ?? ? ? ?? ? ? ?? ? httpd.conf ? ? ? ( httpd.conf ? /etc/apache /etc/httpd ? ?? ? ) AuthPAM_Enabled on AllowOverride None AuthName "Family Secrets" AuthType "basic" require group family ? ?? /var/www ? ?? ??? ? / home/httpd ? ? ? ? ? ? ? ? ? ?? family ? ? ?? ? ? ? Apache ? ? ?? ? ? ?? ? (directive) ? ?? ?? ? ? ?? ?? ?? ? ? ?? ?? ? ? ? ? PAM ? ? ("AuthPAM_enabled on") ? (" AllowOverride none") ? ? "Family Secrets " ? ? ? ("AuthName "Family Secrets"") ? httpd ? (PAM ? ? ??? ) ? ? ? ("AuthType "basic"") ?? ?? ?? family ? ("require group family") ? ? ----------------------------------------------------------------------- 5.6. ?? ? ? ? ? ?? ? ? ?? ? ? ?? ? http://your-domain/family/ ?? ? ?? (your-domain ?? ?? ? ??? (your-domain) ) ? ? ? (uber-authenticator) ??? ?? ----------------------------------------------------------------------- 6. ? ? ??? ? ?? ?? ?? ? ??? ? ? ? ? ? ?? ? ? ? ? ??? ?? ?? ? petehern@yahoo.com ----------------------------------------------------------------------- 6.1. PAM * Linux-PAM System Administrator's Guide * The Linux-PAM Module Writers' Guide * Linux-PAM Application Developer's Manual ----------------------------------------------------------------------- 6.2. ? * linuxsecurity.com * securitywatch.com * Security HOWTO ( ) * Packetstorm ----------------------------------------------------------------------- 6.3. ??? ? ???? ? ? ? ? ?? ? ??? ??? ? ? ? ????? ? ? passwd(5) ????? ? man 5 passwd ? * passwd(5) * crypt(3) * pam.d(5) * group(5) * shadow(5) ----------------------------------------------------------------------- 7. HOWTO ? ? ?? ? ?? ? ??? ? ? ? ? ? ? petehern@yahoo.com ----------------------------------------------------------------------- 7.1. ? ?? ?? Katsunori Aoki ? ? JF@linux.or.jp ysenda@pop01.odn.ne.jp ? ? ?