http://www.ibm.com/developerworks/cn/linux/l-pam/
http://docs.oracle.com/cd/E19253-01/819-7056/ch3pam-01/index.html
http://blog.csdn.net/shenlan211314/article/details/6569592 这篇文章较详细
打开/etc/pam.d/目录下的任何一个配置文件,其中每行的验证规则都使用如下所示的语法格式:
Type Control-flag Module-path Module-arguments
其中每行代表一个独立的验证方式,每个配置文件可以由多种验证规则相互叠加而成。验证时PAM-API会按照从上往下的方式一一读取这些验证规则,并根据其中的控制标志做出相应的动作。
required 某个失败,继续往下,直到所有完成后。
requisite 某个失败,所有结束
sufficient 某个成功,所有结束
验证服务模块-用于授予用户访问帐户或服务的权限。提供此服务的模块可以验证用户并设置用户凭证。
帐户管理模块-用于确定当前用户的帐户是否有效。提供此服务的模块可以检查口令或帐户的失效期以及限时访问。
会话管理模块-用于设置和终止登录会话。
口令管理模块-用于强制实施口令强度规则并执行验证令牌更新。
[root@84-monitor pam.d]# cat sshd
#%PAM-1.0
auth required pam_sepermit.so
auth include password-auth
account required pam_nologin.so
account include password-auth
password include password-auth
# pam_selinux.so close should be the first session rule
session required pam_selinux.so close
session required pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session required pam_selinux.so open env_params
session optional pam_keyinit.so force revoke
session include password-auth
[root@84-monitor pam.d]# cat password-auth-ac
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth required pam_env.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 500 quiet
auth required pam_deny.so
account required pam_unix.so
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid < 500 quiet
account required pam_permit.so
password requisite pam_cracklib.so try_first_pass retry=3 type=
password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
[root@84-monitor pam.d]# cat login
#%PAM-1.0
auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so
auth include system-auth
account required pam_nologin.so
account include system-auth
password include system-auth
# pam_selinux.so close should be the first session rule
session required pam_selinux.so close
session required pam_loginuid.so
session optional pam_console.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session required pam_selinux.so open
session required pam_namespace.so
session optional pam_keyinit.so force revoke
session include system-auth
-session optional pam_ck_connector.so
减号的含义是如果因为系统里没有这个模块而不能载入的话,pam库将不记录日志。
linux-PAM (Pluggable Authentication Modules for linux)是一个共享库套件,它能使本地系统管理员选择应用程序如何认证用户,
常见的应用程序有login,sshd,su,sudo,passwd
login的pam日志,操作为在本地控制台登录输入用户名与密码
Dec 9 11:34:31 localhost login: pam_unix(login:session): session opened for user root by LOGIN(uid=0)
Dec 9 11:34:31 localhost login: ROOT LOGIN ON tty1
Dec 9 11:42:06 localhost login: pam_unix(login:session): session closed for user root
sshd的pam日志,操作为ssh连接一个服务器并输入用户名与密码,查看日志,然后退出
Dec 9 11:38:52 localhost sshd[30208]: Accepted password for root from 192.168.1.88 port 50718 ssh2
Dec 9 11:38:52 localhost sshd[30208]: pam_unix(sshd:session): session opened for user root by (uid=0)
Dec 9 11:40:13 localhost sshd[30208]: pam_unix(sshd:session): session closed for user root
su的pam日志,操作为用普通用户登录,然后su -输入root密码,然后退出
Dec 9 11:46:02 localhost su: pam_unix(su-l:session): session opened for user root by a1(uid=500)
Dec 9 11:47:27 localhost su: pam_unix(su-l:session): session closed for user root
sudo的pam日志,第一条是输入普通用户密码错误,第二条是此普通用户不在sudoers file里
Dec 9 11:58:47 localhost sudo: pam_unix(sudo:auth): authentication failure; logname=a1 uid=500 euid=0 tty=/dev/pts/0 ruser=a1 rhost= user=a1
Dec 9 11:59:00 localhost sudo: a1 : user NOT in sudoers ; TTY=pts/0 ; PWD=/home/a1 ; USER=root ; COMMAND=/bin/df -h
Dec 9 14:16:25 localhost sudo: a1 : TTY=pts/0 ; PWD=/home/a1 ; USER=root ; COMMAND=/sbin/fdisk -l
Dec 9 14:17:03 localhost sudo: a1 : user NOT in sudoers ; TTY=pts/0 ; PWD=/home/a1 ; USER=root ; COMMAND=/sbin/fdisk -l
修改下面,将a1前的#号去掉,即时生效,然后执行sudo时会成功。
[root@localhost pam.d]# visudo
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
#a1 ALL=/bin/df -h,/sbin/fdisk
passwd的pam日志,操作为普通用户登录,然后passwd改自己的密码,第一条日志是当前密码输入错误,第二条是因为太复杂密码不匹配,最后一条是设置成功
Dec 9 11:50:22 localhost passwd: pam_unix(passwd:chauthtok): authentication failure; logname=a1 uid=500 euid=0 tty=pts/0 ruser= rhost= user=a1
Dec 9 11:55:44 localhost passwd: pam_cracklib(passwd:chauthtok): pam_get_authtok_verify returned error: Failed preliminary check by password service
Dec 9 11:57:30 localhost passwd: pam_unix(passwd:chauthtok): password changed for a1