RHEL5 Insert Authentication Module (PAM) Details

Source: Internet
Author: User
RHEL5 plug-in authentication module (PAM)-Linux general technology-Linux programming and kernel information. The following is a detailed description. Based on the Authentication mechanism of Pluggable Authentication Modules (PAM), you can restrict the use of specific applications to the root account. Different modules enable system administrators to set access control policies based on users, passwords, or logon locations.

All the PAM Authentication function libraries are stored in/lib/security/pam _ *. so and called by the corresponding files in the/etc/pam. d/directory. When a request is verified, the application uses the libpam function library to provide services. Which PAM function libraries are used for verification is determined by the corresponding setting file in the/etc/pam. d/directory. Libpam provides the function Sharing Service and can be dynamically loaded.

1 PAM Working Mechanism

The pass or fail result is returned for each authentication module in the/lib/security directory. Some programs use the setting file in the/etc/security directory to determine the authentication method. The application calls the PAM module authentication configuration and stores it in/etc/pam. d. The file name corresponds to the Application name. Each row in the file returns a verification or failure control flag to determine whether the user has access permissions.

2 PAM verification type

* Authenticate the user identity and prompt to enter the account and password.
* The account determines whether to allow access based on the user table, time, or password validity period.
* Password: users are prohibited from logging on repeatedly. password Complexity control is implemented when the password is changed.
* Logs are recorded in sessions, or the number of user logins is limited.

The libpam function library can call one or all of the preceding services.

3. Control Values)

The verification Control type can also be called Control Flags, which is used to return results of the PAM verification type.

* The request continues when the verification fails, but returns Fail (the user does not know where the failure is)
* If requisite verification fails, the entire verification process is completed immediately and Fail is returned.
* If sufficient is successfully verified, the system returns immediately and does not continue. Otherwise, the system ignores the result and continues.
* Optional does not affect the verification result (usually used for session type)

Verification Result table
┌ ── ─ ┬ ── ─
│ Result │ Keep testing? │ Affect │
├ ── ─ ┼ ── ─
│ Pass │ Y │ Define by system │
│ Required │ Fail │ Y │ Fail │
├ ── ─ ┼ ── ─
│ Requisite │ Pass │ Y │ Define by system │
│ Fail │ N │ Fail │
├ ── ─ ┼ ── ─
│ Sufficient │ Pass │ N │ Define by system │
│ Fail │ Y │ Ignore │
└ ── ─ ┴ ── ─

Verification Example 1
┌ ── ─ ┬ ──
│ User1 │ user2 │ user3 │
├ ── ─ ┼ ──
│ Auth │ Required │ Module1 │ Pass │ Fail │ Pass │
├ ── ─ ┼ ──
│ Auth │ Required │ Module2 │ Pass │ Fail │
├ ── ─ ┼ ──
│ Auth │ Required │ Module3 │ Pass │ Fail │
├ ── ─ ┴ ── ─ ┼ ──
│ Result │ Pass │ Fail │
└ ── ─

Verification Example 2
── ─ ┬ ── ─
│ User1 │ user2 │ user3 │
── ─ ┼ ── ─
│ Auth │ Required │ Module1 │ Pass │ Fail │ Pass │
── ─ ┼ ── ─
│ Auth │ Sufficient │ Module2 │ Pass │ Fail │
── ─ ┼ ── ─
│ Auth │ Required │ Module3 │ N/A │ Pass │
── ─ ┴ ── ─
│ Result │ T │ F │ T │
└ ── ─

4. configuration file in the/etc/pam. d directory

Each configuration file has four columns: The verification type in the first column, the verification control standard in the second column, the PAM module called in the third column, and the parameters used in the fourth column.

Module_type control_flag module_location arguments

Each row of records is a periodic test.

[Root @ wardking ~] # Cat/etc/pam. d/system-auth
# % 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_succeed_if.so uid <500 quiet
Account required pam_permit.so

Password requisite pam_cracklib.so try_first_pass retry = 3
Password sufficient pam_unix.so md5 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

The modules called by auth and account directly affect whether the user can execute the program.

Password is used when the user changes the password.

Session is used to record operation records after successful user verification.

5 pam_stack special modules

When multiple applications need to use the same verification module, You can edit a pam setting file to define the module to be called together and store it in/etc/pam. d directory, which can be called by a program. For example, the system-auth setting file can be called by different applications. If you modify the file, you can change the system verification policy.

6 pam_unix Module

You can call a traditional NSS system, namely, the libnss function library. It can be used for PAM's four authentication methods. auth can be used to obtain the user's password, and accont can be used to check whether the user's password has expired ,, you can use the password method to check the user's control when changing the password, and use the session method to record the user's logon and logout logs.

7. network verification

Users can be verified through network login

* Pam_krb5 (Kerberos V tickets)
* Pam_ldap (LDAP binds)
* Pam_smb_auth (old SMB authentication)
* Pam_winbind (SMB throuth winbind)

Some name services can also use pam_unix to call the modules in the libnss function library for verification (NIS, Some LDAP comprehensions), rather than using the above four modules.

8. Authentication Module

The pam_security module only affects root users. When the root account is logged on, pam_security will refer to the console list in the/etc/securetty directory to determine whether the root account can be logged on, so as to prevent users from logging on from insecure terminals.

The pam_nologin module will check whether the/etc/nologin file exists. If yes, normal users will fail to verify and only allow root users to log on.

The pam_listfile Module checks whether the user account to be logged on conflicts with the list of permitted accounts. A list of permitted or denied logon must be created.

Auth required pam_listfile item = user sense = deny file =/etc/vsftpd/ftpusers onerr = succeed

9. Enhance User Password Security

Pam_unix has two parameters to enhance user password security

* Pam_unix MD5 passwords encryption using MD5 Encoding
* Pam_unix shadow passwords stores the encrypted password in the/etc/shadow file, restricts normal user access, and limits the password validity period.

Other modules can play a similar role, such as pam_krb5.

10 password security principles

It can be defined that common users must follow certain policies when setting passwords.

* Password history records the passwords used by users.
Pam_unix with remember = N (records the first N passwords used by the user and prohibits the re-use of these passwords)

* Pasword length and complexity
The pam_cracklib module requires that you use uppercase and lowercase letters, numbers, and special characters as passwords and cannot use words in dictionaries.
The pam_passwdqc module is similar to cracklib, but does not check words in the dictionary.

* Failed login monitoring
The account is locked if the pam_taily logon fails too many times.

11 pam_limit

Pam_limit limits the system resources that can be used by users, calls the/etc/security/limits. conf file, limits the memory used by users, and the number of threads that can be enabled

# * Soft core 0
# * Hard rss 10000
# @ Student hard nproc 20
# @ Faculty soft nproc 20
# @ Faculty hard nproc 50
# Ftp hard nproc 0
# @ Student-maxlogins 4

You can use ulimit to override soft settings, but it is still limited by hard

12 pam_console

Pam_console module: After you log on to the console, you will have some special permissions. These permissions are defined in the/etc/security/console. apps directory.

For example, a user has the permission to restart the computer after logging on.

[Root @ wardking ~] # Cat/etc/security/console. apps/reboot
FALLBACK = true

It can also be used in the auth authentication type. After a user successfully logs on to the local computer, other remote login requests are rejected.

13 other programs call PAM

In addition to user login verification, verification is also required when common users use system management tools, such as su, reboot, and system-* tools.

The pam_rootok module is used to confirm whether the user is a root identity.

The pam_timestamp module is used to record the time interval for the user to execute sudo. If the verification succeeds within five minutes, it passes the verification directly without entering the password.

The pam_xauth module is used to forward verification temporary files to other programs.

14. instance analysis

[Root @ wardking ~] # Cd/etc/pam. d
[Root @ wardking pam. d] # cat config-util
# % PAM-1.0
Auth sufficient pam_rootok.so
Auth sufficient pam_timestamp.so
Auth include system-auth
Account required pam_permit.so
Session required pam_permit.so
Session optional pam_xauth.so
Session optional pam_timestamp.so

/Etc/pam. d/config-util is a special module of the pam_stack type, which is provided to multiple applications, such as system-config.

Auth sufficient pam_rootok.so

This command checks the user's identity and calls the pam_rootok.so module. If the verified user is root, the system returns Pass. If it is not a root user, Fail is returned. Because this command uses the sufficient control flag, subsequent commands will be executed even if the verification fails.

Auth sufficient pam_timestamp.so

If the verification of the First Command fails, you can determine that the currently authenticated user is a common user. Therefore, use the pam_timestamp.so module in the second command to check whether the sudo command has been successfully run by the user within five minutes. If the sudo command is returned, Pass is returned. Otherwise, Fail is returned. This command also uses the sufficient control flag, so Subsequent commands will be executed when verification fails.

Auth include system-auth

The third command uses the pam_stack.so module to call the system-auth configuration file in the current directory. System-auth defines many PAM command statements. Its main function is to prompt common users to enter the password of the root account.

Account required pam_permit.so

The fourth command calls the pam_permit.so module as an account to allow or deny access based on the validity of the current account (whether the account is disabled or expired. Because the command is executed with the required control flag, if the verification result is still Fail, the verification fails throughout the process.

The last three session commands record the entire verification process and write it to/var/log/secure.

15 Fault Detection

When system verification fails, check the output information in/var/log/messages or/var/log/secure to determine the validity of the user account. If the root user cannot log on because of a PAM verification failure, the single user or rescue mode can only be used for troubleshooting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.