https://access.redhat.com/articles/8994
Updated 2012年九月16日10:04 -
-
Below is a sample PAM application configuration file:
#%PAM-1.0 auth required pam_securetty.so auth required pam_unix.so shadow nullok auth required pam_nologin.so account required pam_unix.so password required pam_cracklib.so retry=3 password required pam_unix.so shadow nullok use_authtok session required pam_unix.soThe first line is a comment as denoted by the hash mark (#) at the beginning of the line.
Lines two through four stack three modules for login authentication.
auth required pam_securetty.soThis module makes sure that if the user is trying to log in as root, the tty on which the user is logging in is listed in the
/etc/securettyfile, if that file exists.auth required pam_unix.so shadow nullokThis module prompts the user for a password and then checks the password using the information stored in
/etc/passwdand, if it exists,/etc/shadow. Thepam_unix.somodule automatically detects and uses shadow passwords to authenticate users.The argument
nullokinstructs thepam_unix.somodule to allow a blank password.auth required pam_nologin.soThis is the final authentication step. It verifies whether or not the file
/etc/nologinexists. Ifnologindoes exist and the user is not root, authentication fails.Note: In this example, all three auth modules are checked, even if the first auth module fails. This prevents the user from knowing at what stage their authentication failed. Such knowledge in the hands of an attacker could allow them to more easily deduce how to crack the system.
account required pam_unix.soThis module performs any necessary account verification. For example, if shadow passwords have been enabled, the account component of the
pam_unix.somodule checks to see if the account has expired or if the user has not changed the password within the grace period allowed.password required pam_cracklib.so retry=3If a password has expired, the password component of the
pam_cracklib.somodule prompts for a new password. It then tests the newly created password to see whether it can easily be determined by a dictionary-based password cracking program. If it fails this test the first time, it gives the user two more chances to create a strong password, as specified in theretry=3argument.password required pam_unix.so shadow nullok use_authtokThis line specifies that if the program changes the user's password, it should use the
passwordcomponent of thepam_unix.somodule to do so. This only happens if theauthportion of thepam_unix.somodule has determined that the password needs to be changed.The argument
shadowtells the module to create shadow passwords when updating a user's password.The argument
nullokinstructs the module to allow the user to change their password from a blank password, otherwise a null password is treated as an account lock.The final argument on this line,
use_authtok, provides a good example of the importance of order when stacking PAM modules. This argument tells the module not to prompt the user for a new password. Instead, it accepts any password that was recorded by a previous password module. In this way all, new passwords must pass thepam_cracklib.sotest for secure passwords before being accepted.session required pam_unix.soThe final line specifies that the session component of the
pam_unix.somodule manages the session. This module logs the username and the service type to/var/log/messagesat the beginning and end of each session. It can be supplemented by stacking it with other session modules for more functionality. -
The next sample configuration file illustrates
authmodule stacking for therloginprogram.#%PAM-1.0 auth required pam_nologin.so auth required pam_securetty.so auth required pam_env.so auth sufficient pam_rhosts_auth.so auth required pam_stack.so service=system-authFirst,
pam_nologin.sochecks to see if/etc/nologin exists. If it does, no one can log in except for root.auth required pam_securetty.soThe
pam_securetty.somodule prevents the root user from logging in on insecure terminals. This effectively disallows all rootrloginattempts due to the application's limited security safeguards.Tip: To log in remotely as the root user, use OpenSSH instead.
auth required pam_env.soThis line loads the
pam_env.somodule, which sets the environmental variables specified in/etc/security/pam_env.conf.auth sufficient pam_rhosts_auth.soThe
pam_rhosts_auth.somodule authenticates the user using.rhostsin the user's home directory. If this succeeds, PAM immediately considers the authentication to have succeeded. Ifpam_rhosts_auth.sofails to authenticate the user, the authentication attempt is ignored.auth required pam_stack.so service=system-authIf the
pam_rhosts_auth.somodule fails to successfully authenticate the user, thepam_stack.somodule performs normal password authentication.The argument
service=system-authindicates that the user must now pass through the PAM con- figuration for system authentication as found in/etc/pam.d/system-auth.Tip: To prevent PAM from prompting for a password when the securetty result fails, change the
pam_securetty.somodule fromrequired to requisite.
本文深入解析了PAM(Pluggable Authentication Modules)模块在Linux系统中的应用配置,详细阐述了各个模块的功能,如pam_securetty.so、pam_unix.so、pam_nologin.so等在登录认证、账户验证、密码管理和会话管理中的作用。
285

被折叠的 条评论
为什么被折叠?



