linux取消密码复杂度限制 笔记240306

linux取消密码复杂度限制

echo root|passwd --stdin root

在Linux系统中,密码复杂度通常是由PAM(Pluggable Authentication Modules)来控制的。要取消密码复杂度限制,你需要编辑PAM的配置文件。

请注意,取消密码复杂度限制可能会降低系统的安全性。在做出这个更改之前,请确保你了解潜在的安全风险,并仔细考虑是否真的需要这样做。

以下是在大多数Linux发行版上取消密码复杂度限制的一般步骤:

  1. 打开终端或SSH连接到你的Linux系统。
  2. 使用root或具有sudo权限的用户登录。
  3. 找到PAM的配置文件。在大多数Linux发行版中,密码复杂度配置通常位于/etc/pam.d/common-password/etc/pam.d/password-auth文件中。你可以使用文本编辑器(如nano、vim等)打开这些文件。

例如,使用nano编辑器打开/etc/pam.d/common-password文件:

sudo vi /etc/pam.d/common-password
sudo nano /etc/pam.d/common-password

红帽系

sudo vi /etc/pam.d/password-auth
sudo nano /etc/pam.d/password-auth
  1. 在打开的文件中,找到包含密码复杂度规则的行。这些行通常以pam_pwquality.so开头,并包含一些选项和参数。

例如,你可能会看到类似下面的行:

password requisite pam_pwquality.so retry=3 minlen=8 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1 enforce_for_root

这行代码设置了一些密码复杂度要求,包括最小长度(minlen)、数字字符数量(dcredit)、大写字母数量(ucredit)、小写字母数量(lcredit)和其他字符数量(ocredit)等。
5. 要取消密码复杂度限制,你可以将这行注释掉(在行首添加#符号),或者完全删除该行。注释掉的示例如下:

# password requisite pam_pwquality.so retry=3 minlen=8 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1 enforce_for_root
  1. 保存并关闭文件。在nano编辑器中,按下Ctrl + X,然后输入Y确认保存。
  2. 现在,你已经成功取消了密码复杂度限制。请注意,这个更改会立即生效,但已经设置的密码不会受到影响。只有在下次更改密码时,新的密码要求才会生效。

请记住,取消密码复杂度限制可能会使你的系统更容易受到密码猜测和暴力破解等攻击。在做出这个更改之前,请务必权衡安全性和便利性之间的平衡,并采取其他安全措施来保护你的系统。







BAD PASSWORD: The password contains less than 1 digits

如果您在尝试设置密码时收到错误消息“BAD PASSWORD: The password contains less than 1 digits”(密码错误:密码包含的数字少于1个),这意味着您的系统或应用程序的密码策略要求密码中至少包含一个数字。

要解决这个问题,您需要确保您的新密码包含至少一个数字(0-9)。例如,如果您的原始密码是“password”,您需要将其更改为“password1”或“p4ssword”等,以满足密码策略的要求。

如果您认为这个密码策略过于严格或不必要,并且您希望更改它,您可以按照之前提到的步骤编辑PAM的配置文件来修改密码策略。但是,请注意,降低密码复杂度要求可能会降低系统的安全性。

如果您确实需要修改PAM配置来取消或更改密码策略,请按照以下步骤操作:

  1. 打开PAM密码策略配置文件。这个文件可能是/etc/pam.d/common-password/etc/pam.d/password-auth或其他类似的文件,具体取决于您的Linux发行版。
sudo vi /etc/pam.d/common-password
sudo nano /etc/pam.d/common-password

红帽系

sudo vi /etc/pam.d/password-auth
sudo nano /etc/pam.d/password-auth
  1. 找到包含pam_pwquality.so的行。这行可能看起来像这样:
password requisite pam_pwquality.so retry=3 minlen=8 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1 enforce_for_root

在这个例子中,dcredit=-1表示密码中至少需要包含一个数字。如果您想要取消这个要求,可以将dcredit=-1更改为dcredit=0。但是,请注意,将dcredit设置为0实际上会禁止密码中包含数字,这不是您想要的结果。如果您想要移除数字要求,您应该完全移除dcredit选项,或者将其注释掉。

然而,如果您只是想要更改数字的最小数量要求,您可以调整dcredit的值。例如,将dcredit=-1更改为dcredit=2将要求密码中至少包含2个数字。但请注意,通常dcredit的负值表示“至少”要求,而正值表示“最多”要求,但这个行为可能因PAM版本和配置而异。因此,在修改这些值之前,请查阅相关文档以确认其含义。

实际上,如果您想要确保密码中至少包含一个数字,您应该保持dcredit=-1不变或将其设置为一个更大的负数(虽然这通常没有必要)。

  1. 如果您做了任何更改,请保存并关闭文件。
  2. 测试新的密码策略是否按预期工作。尝试设置一个不包含数字的密码,看看系统是否接受它。如果不接受,请检查您的更改是否正确应用。

请记住,在修改PAM配置之后,您可能需要重新登录或重启服务才能使更改生效。此外,始终在修改系统配置文件之前备份原始文件,以防万一出现问题您可以恢复到原始状态。










OpenCloudOS使用简单密码

OpenCloudOS 是一种基于 Linux 的开源操作系统,通常用于云计算环境。像大多数 Linux 发行版一样,OpenCloudOS 也使用 PAM (Pluggable Authentication Modules) 来管理用户认证,包括密码策略。

如果您希望在 OpenCloudOS 中使用简单密码,您需要修改 PAM 的配置来放宽密码策略。但是,请注意,使用简单密码会降低系统的安全性,使您的系统更容易受到攻击。

以下是在 OpenCloudOS(或类似的基于 Linux 的系统)中放宽密码策略的一般步骤:

  1. 备份当前配置:在修改任何系统配置之前,建议先进行备份。

    sudo cp /etc/pam.d/common-password /etc/pam.d/common-password.bak
    
  2. 编辑 PAM 配置:使用文本编辑器(如 nanovim)编辑 /etc/pam.d/common-password 文件。

    sudo nano /etc/pam.d/common-password
    
  3. 找到密码策略行:寻找包含 pam_pwquality.so 的行,这通常是设置密码策略的地方。

    password requisite pam_pwquality.so retry=3 minlen=8 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1 enforce_for_root
    
  4. 修改或注释掉策略:您可以注释掉这行(在前面添加 # 符号),或者修改参数以放宽密码要求。例如,您可以将 minlen(最小长度)设置为一个较小的数字,或者将 dcreditucreditocreditlcredit 设置为 0 来移除对特定类型字符的要求。

    注意:将任何 credit 参数设置为正数实际上会限制密码中该类字符的最大数量,而不是最小数量。要移除对特定类型字符的要求,您应该将其设置为负数或完全移除该选项。

  5. 保存并关闭文件:在 nano 中,按 Ctrl + O 保存,然后按 Ctrl + X 退出。

  6. 测试新配置:尝试设置一个简单密码来验证新配置是否生效。

    passwd username
    

    然后输入您希望设置的新密码。

  7. 重启服务或系统(可选):虽然通常不需要重启整个系统,但某些服务可能需要重启才能应用新的 PAM 配置。

请记住,放宽密码策略会增加系统被攻击的风险。在做出此类更改之前,请确保您了解潜在的安全隐患,并考虑实施其他安全措施来降低风险,例如使用防火墙、VPN、定期更新和补丁管理等。如果可能的话,最好是实施更强的密码策略和其他身份验证方法,如多因素身份验证。




centos 设置密码复杂度

在 CentOS 系统中,密码复杂度是通过 PAM(Pluggable Authentication Modules)来控制的。要设置密码复杂度,需要编辑 PAM 的配置文件。以下是设置 CentOS 密码复杂度的一般步骤:

  1. 备份原有的 PAM 配置文件,以防止意外修改导致问题。可以使用以下命令备份:
sudo cp /etc/pam.d/system-auth /etc/pam.d/system-auth.bak
  1. 使用文本编辑器(如 vim)打开 /etc/pam.d/system-auth 文件:
sudo vim /etc/pam.d/system-auth
  1. 在该文件中,找到包含 pam_pwquality.so 的行。这是控制密码复杂度的模块。

  2. 根据需要修改该行的参数来设置密码复杂度。以下是一些常用的参数及其含义:

    • minlen=N:密码最小长度。将 N 替换为所需的最小长度值。
    • dcredit=N:密码中必须包含的数字的最小数量。将 N 替换为所需的数字数量。注意,负数表示至少包含多少个数字,正数表示最多包含多少个数字。但是,通常使用负数来设置最小要求。
    • ucredit=N:密码中必须包含的大写字母的最小数量。同样地,将 N 替换为所需的大写字母数量,并使用负数表示至少包含多少个。
    • lcredit=N:密码中必须包含的小写字母的最小数量。将 N 替换为所需的小写字母数量,并使用负数表示至少包含多少个。
    • ocredit=N:密码中必须包含的特殊字符的最小数量。将 N 替换为所需的特殊字符数量,并使用负数表示至少包含多少个。例如,要将密码长度设置为至少 12 个字符,并要求至少包含一个大写字母、一个小写字母、一个数字和一个特殊字符,可以这样修改行:
password requisite pam_pwquality.so minlen=12 dcredit=-1 ucredit=-1 lcredit=-1 ocredit=-1
  1. 保存并关闭文件。在 vim 中,按 Esc 键退出编辑模式,然后输入 :wq 保存并退出。
  2. 测试新密码策略是否生效。可以尝试使用不符合新策略的密码进行更改,并验证系统是否拒绝该密码。

请注意,修改 PAM 配置文件需要管理员权限。确保在进行任何更改之前备份相关文件,并仔细验证所做的更改是否符合您的需求。另外,密码复杂度的设置可能因 CentOS 版本和具体配置而有所不同,请参考相关文档或官方指南以获取更详细的信息。

The password is a palindrome 密码是回文

If you want to enforce a policy that prevents users from setting passwords that are palindromes (i.e., read the same forwards and backwards), you’ll need to customize the PAM configuration on your CentOS system. However, the pam_pwquality module, which is commonly used to enforce password policies on Linux systems, does not have a built-in option to specifically check for palindromes.

To implement such a check, you can write a custom PAM module or use a script with the pam_exec module to perform the palindrome check during the password change process. However, writing a custom PAM module requires C programming skills and a good understanding of the PAM API.

A simpler, though less elegant, solution would be to use the pam_cracklib or pam_pwquality module’s ability to execute an external program or script as part of the password checking process. However, please note that as of recent updates to the Linux PAM stack, pam_cracklib is deprecated in favor of pam_pwquality, which does not directly support executing external commands.

Instead, you can use the pam_exec module to run a script that checks for palindromes. Here’s a basic outline of how you might approach this:

  1. Create a script to check for palindromes:

    Write a script (e.g., /usr/local/bin/check_palindrome.sh) that takes a password as input and checks if it is a palindrome. If it is, the script should exit with a non-zero status to indicate failure. Here’s a simple bash script example:

    #!/bin/bash
    
    # Read the password from stdin
    read -r password
    
    # Check if the password is a palindrome
    if [[ "$password" == "$(echo "$password" | rev)" ]]; then
        exit 1  # Exit with a non-zero status if it is a palindrome
    else
        exit 0  # Exit with a zero status if it is not a palindrome
    fi
    

    Make sure to make the script executable:

    chmod +x /usr/local/bin/check_palindrome.sh
    
  2. Modify the PAM configuration:

    Edit the /etc/pam.d/system-auth file (or the appropriate PAM configuration file for password changes) and add a line to call your script using the pam_exec module. This should be done before the pam_unix module’s password line.

    password requisite pam_exec.so quiet /usr/local/bin/check_palindrome.sh
    

    The quiet option prevents the output of the script from being displayed to the user.

  3. Test the configuration:

    After making changes to the PAM configuration, test the new policy by attempting to change a user’s password to a palindrome and then to a non-palindrome to verify that the policy is enforced correctly.

Please note that modifying PAM configuration can affect system security and accessibility, so it’s important to test any changes thoroughly in a safe environment before deploying them to a production system. Additionally, be aware that custom scripts and modules can introduce vulnerabilities if not implemented correctly.

If you want to enforce a policy that prevents users from setting passwords that are palindromes (i.e., read the same forwards and backwards), you will need to write a custom PAM (Pluggable Authentication Modules) module or use a script with an existing PAM module like pam_exec.so to check for this condition.

CentOS, like most Linux distributions, does not have a built-in PAM module specifically for checking if a password is a palindrome. However, you can use the pam_exec.so module to execute a script that performs this check.

Here’s a basic outline of how you might set this up:

  1. Create a script to check for palindromes:

Write a script in a language like Bash or Python that takes a password as input and checks if it is a palindrome. The script should exit with a status code of 0 if the password is not a palindrome and a non-zero status code if it is.

For example, here’s a simple Bash script that does this:

#!/bin/bash

# Read the password from stdin
read -r password

# Reverse the password
reversed=$(echo "$password" | rev)

# Check if the password is a palindrome
if [[ "$password" == "$reversed" ]]; then
    exit 1  # Palindrome detected, exit with non-zero status
else
    exit 0  # Not a palindrome, exit with zero status
fi

Save this script somewhere like /usr/local/bin/check_palindrome.sh and make it executable with chmod +x /usr/local/bin/check_palindrome.sh.

  1. Modify the PAM configuration:

Edit the /etc/pam.d/system-auth file (or the appropriate PAM configuration file for password changes) and add a line to use the pam_exec.so module to run your script. You want to add this line to the “password” section of the file, likely after any existing pam_pwquality.so line.

password requisite pam_exec.so quiet /usr/local/bin/check_palindrome.sh

The quiet option prevents the output of the script from being displayed to the user. The path after pam_exec.so should point to your palindrome-checking script.

  1. Test the configuration:

Try changing your password to a palindrome and verify that the system rejects it. Also, test with a non-palindrome password to ensure that regular password changes still work.

  1. Troubleshooting:

If you encounter any issues, check the system logs (e.g., /var/log/secure or /var/log/auth.log, depending on your system configuration) for PAM-related messages. These logs can provide clues as to why a PAM module might be failing.

Remember that modifying PAM configurations can affect system security and authentication, so it’s important to test changes thoroughly and have a backup of any modified files.

The password is shorter than 6 characters

To enforce a password policy that requires passwords to be at least 6 characters long (or any other minimum length you choose), you can use the pam_pwquality.so module in CentOS with the minlen parameter. Here’s how to set it up:

  1. Open the /etc/pam.d/system-auth file for editing with root privileges:
sudo vi /etc/pam.d/system-auth
  1. Locate the line that begins with password requisite pam_pwquality.so. This line might already contain some parameters. If not, you can add it.

  2. Add or modify the minlen parameter to set the minimum password length. For example, to require a minimum length of 6 characters, you would add minlen=6 like this:

password requisite pam_pwquality.so minlen=6

If there are already other parameters present, simply append minlen=6 to the end of the line, separated by spaces:

password requisite pam_pwquality.so try_first_pass local_users_only retry=3 minlen=6
  1. Save the file and exit the editor.

  2. Test the new password policy by trying to set a password shorter than 6 characters. You should receive an error message indicating that the password is too short.

  3. If everything works as expected, you’re done! If not, double-check your changes and make sure there are no syntax errors in the PAM configuration file.

Remember that changes to PAM configuration files take effect immediately, so you don’t need to restart any services. However, it’s always a good idea to have a backup of the original file before making any changes.

Note: The pam_pwquality.so module might also be configured in the /etc/pam.d/password-auth file, depending on your system setup. If that’s the case, you might need to make the same changes there as well to ensure the policy is enforced consistently.




pam_pwquality.so

pam_pwquality.so 是一个 PAM (Pluggable Authentication Modules) 模块,用于在 Linux 系统中检查和限制用户密码的复杂度。它提供了一种方法来实施密码策略,确保用户设置的密码符合特定的安全性要求。

该模块的主要功能和参数包括:

  • 密码长度:通过 minlen 参数设置密码的最小长度。例如,minlen=8 会要求密码至少包含 8 个字符。

  • 密码组成:可以使用 ucreditlcreditdcreditocredit 参数来分别指定密码中必须包含的大写字母、小写字母、数字和特殊字符的最小数量。例如,ucredit=-1 表示密码中至少必须有一个大写字母。

  • 旧密码相似性检查difok 参数用于设置新密码与旧密码之间必须有多少个字符不同。例如,difok=3 意味着新密码必须与旧密码至少有 3 个字符不同。

  • 重试次数retry 参数定义了用户在设置密码时可以尝试的次数,超过这个次数后,操作将被拒绝。

  • 其他选项:还有其他一些选项,如 enforce_for_root(决定是否对 root 用户强制执行密码策略)和 try_first_pass(尝试使用前一个模块留下的密码,而不是提示用户再次输入)。

要在系统中使用 pam_pwquality.so 模块,你需要在相应的 PAM 配置文件中添加或修改一行,通常是在 /etc/pam.d/system-auth/etc/pam.d/password-auth 文件中。例如:

password requisite pam_pwquality.so retry=3 minlen=8 dcredit=-1 ucredit=-1 lcredit=-1 ocredit=-1

这行代码表示:

  • 密码设置是必需的(requisite)。
  • 使用 pam_pwquality.so 模块。
  • 允许用户重试 3 次(retry=3)。
  • 密码最小长度为 8 个字符(minlen=8)。
  • 密码中至少包含 1 个数字(dcredit=-1)。
  • 密码中至少包含 1 个大写字母(ucredit=-1)。
  • 密码中至少包含 1 个小写字母(lcredit=-1)。
  • 密码中至少包含 1 个特殊字符(ocredit=-1)。

配置完成后,当用户尝试更改或设置密码时,系统将按照这些规则检查密码的复杂性。如果密码不符合要求,系统将拒绝更改并显示相应的错误消息。




pam_pwhistory.so

pam_pwhistory.so 是另一个 PAM (Pluggable Authentication Modules) 模块,它用于在 Linux 系统中检查新密码是否在最近的密码历史记录中。这有助于防止用户重复使用相同的密码或在密码历史中使用简单的变种,从而增强密码的安全性。

pam_pwhistory.so 模块的主要功能和参数包括:

  • 密码历史记录文件:通常,密码历史记录存储在一个特定的文件中,如 /etc/security/opasswd。但是,在现代系统上,更常见的是使用阴影密码文件(/etc/shadow)中的保留字段来存储密码历史记录。

  • 密码历史长度remember 参数用于指定要保留在密码历史记录中的密码数量。例如,remember=5 将保留最近的 5 个密码。

  • 密码重用策略:模块可以防止用户在密码历史记录中重复使用相同的密码。这可以通过设置适当的 remember 值来实现。

  • 密码哈希兼容性:该模块需要与系统上存储密码哈希的方式兼容,通常与 /etc/shadow 文件或其他密码存储机制一起使用。

要在系统中使用 pam_pwhistory.so 模块,你需要在相应的 PAM 配置文件中添加或修改一行。但是,请注意,在许多现代 Linux 发行版中,pam_pwhistory.so 已经被 pam_pwquality.so 的内置历史记录功能所取代,因此你可能不需要单独配置 pam_pwhistory.so

如果你的系统确实支持并使用 pam_pwhistory.so,你可以在 /etc/pam.d/common-password 或其他相关的 PAM 配置文件中找到类似以下的行:

password requisite pam_pwhistory.so remember=5 use_authtok

这行代码表示:

  • 密码设置是必需的(requisite)。
  • 使用 pam_pwhistory.so 模块。
  • 保留最近的 5 个密码在历史记录中(remember=5)。
  • 使用当前认证令牌(即用户输入的密码)进行检查(use_authtok)。

然而,再次强调,许多现代系统已经转向使用 pam_pwquality.so 的内置功能来处理密码历史和复杂性要求,因此在实际配置中可能看不到 pam_pwhistory.so 的显式使用。在这种情况下,你应该查阅你的 Linux 发行版的文档或 pam_pwquality.so 的手册页来了解如何配置这些功能。




pam_sss.so

pam_sss.so 是 Linux PAM (Pluggable Authentication Modules) 中的一个模块,用于与 SSSD (System Security Services Daemon) 进行交互。SSSD 是一个守护进程,它提供对多种身份验证和授权提供程序(如 LDAP、Kerberos、Active Directory 等)的访问。通过 pam_sss.so,PAM 能够利用 SSSD 提供的这些服务来执行用户身份验证。

当配置了 pam_sss.so 之后,PAM 会在需要验证用户身份时调用 SSSD。SSSD 则会与用户指定的身份验证后端进行通信,以验证提供的凭据是否正确。如果验证成功,用户将被允许访问系统;如果验证失败,用户将被拒绝访问。

在 PAM 配置文件中,pam_sss.so 的使用通常看起来像这样:

auth sufficient pam_sss.so use_first_pass

这里的 auth 表示这是一个认证模块,sufficient 表示如果此模块成功,则不再需要其他模块的认证。use_first_pass 参数告诉 PAM 使用前一个模块留下的密码,这样用户就不必再次输入密码。

pam_sss.so 模块本身通常不需要额外的参数,因为它会依赖于 SSSD 的配置来确定如何与后端服务进行通信。SSSD 的配置文件通常位于 /etc/sssd/sssd.conf,并且需要正确配置以指向适当的身份验证和授权服务器。

使用 pam_sss.so 和 SSSD 的好处是,它们提供了一个集中的身份验证和授权机制,可以轻松地与多个不同的身份验证源进行集成。这对于管理大型网络环境中的用户访问非常有用,特别是当用户信息存储在目录服务(如 LDAP 或 Active Directory)中时。







pam_deny.so

pam_deny.so 是 Linux PAM (Pluggable Authentication Modules) 中的一个模块,它的作用非常简单且直接:拒绝任何认证请求。当这个模块被配置为某个服务或应用程序的一部分时,任何尝试通过该服务进行身份验证的用户都会被拒绝,无论他们提供什么凭据。

这个模块通常用于明确地拒绝某些类型的访问,或者作为一个“失败安全”机制,在认证链的末尾捕获所有未被前面的模块处理的请求。例如,如果一个系统管理员想要确保某个特定的服务不被任何人使用,他们可以在该服务的 PAM 配置中包含 pam_deny.so

在 PAM 配置文件中,pam_deny.so 的使用通常看起来像这样:

auth required pam_deny.so

或者更简单地:

auth required /lib/security/pam_deny.so

这里的 auth 表示这是一个认证模块,required 表示这个模块必须成功执行(在这种情况下,它总是失败,因为 pam_deny.so 的任务就是拒绝所有请求)。实际的模块路径可能会根据你的系统和安装方式有所不同。

然而,需要注意的是,将 pam_deny.so 设置为 required 实际上意味着如果它被执行,认证将总是失败。因此,在大多数情况下,你可能更希望将其设置为 sufficient,这样一旦它被执行,后续的模块将不会被调用,因为认证已经被拒绝了。但在实践中,由于 pam_deny.so 的行为是立即拒绝,所以将其设置为 requiredsufficient 的效果实际上是相同的。不过,为了清晰和符合 PAM 的常规用法,你可能会看到它被配置为 sufficient 的情况更多一些:

auth sufficient pam_deny.so

但是请注意,在认证堆栈中放置 pam_deny.so 作为 sufficient 需要谨慎,因为它会阻止后续的任何模块被调用。这通常只在你确定想要拒绝所有访问时才这样做。在大多数情况下,你可能想要将它放在认证堆栈的末尾,作为最后的拒绝手段,而不是放在开头立即拒绝所有请求。




Linux PAM (Pluggable Authentication Modules)

Linux PAM(Pluggable Authentication Modules,可插拔认证模块)是一种灵活的身份验证框架,它为Linux系统提供了一种标准化的、模块化的方式来管理用户认证。PAM允许系统管理员根据特定的安全需求选择和配置不同的身份验证方法,而无需修改底层应用程序的代码。

PAM的工作原理是将身份验证过程分解为一系列可配置的模块。每个模块都负责执行特定的身份验证任务,例如验证用户的密码、检查账户状态、限制登录时间等。这些模块可以根据需要进行组合和配置,以实现复杂的身份验证策略。

当用户尝试访问系统资源时(例如登录到系统或执行特权操作),PAM会根据配置文件中的规则按顺序调用相应的模块进行身份验证。每个模块都会根据其配置执行特定的检查,并返回成功或失败的结果。PAM会根据这些结果决定是否允许用户访问系统。

PAM的配置文件通常位于/etc/pam.d/目录下,每个应用程序或服务都有一个对应的PAM配置文件。这些配置文件定义了身份验证过程中要使用的模块以及它们的顺序和参数。通过编辑这些配置文件,管理员可以灵活地调整身份验证策略,以满足特定的安全需求。

PAM提供了许多内置的身份验证模块,用于执行各种常见的身份验证任务。此外,第三方开发者也可以编写自己的PAM模块来扩展功能。这使得PAM成为了一个非常强大和灵活的身份验证框架,可以适应各种不同的安全场景和需求。

总之,Linux PAM是一个可插拔的身份验证框架,通过模块化的方式实现了灵活的身份验证策略管理。它使得系统管理员能够轻松地配置和定制身份验证过程,以满足特定的安全需求。

Linux下PAM认证详解(以centos7为例)

pam的配置文件

1)pam的配置文件当中为每种应用定义其需要用到的模块,包括驱动、授权机制等。
	2)配置文件
		模块文件目录:	/lib64/security/*.so
		模块配置文件:	/etc/security/*.conf
		环境相关的设置:	/etc/security/
		主配置文件:	/etc/pam.conf ,默认不存在。
		次级配置文件目录:	/etc/pam.d/,该配置文件目录下的每个配置文件都对应一个应用模块的专用配置文件
		注意:
			如/etc/pam.d 存在,/etc/pam.conf 将失效
	3)模块通过读取模块配置文件完成用户对系统资源的使用控制
	4)注意:修改PAM 配置文件将马上生效
	5)建议:编辑pam规则时 ,保持至少打开一个root会话,以防止root 身份验证错误
	6)通用配置文件/etc/pam.conf 格式
		application 、type 、control 、module-path 、module-arguments
	7)专用配置文件/etc/pam.d/* 格式
		type、control、module-path、module-arguments
	8)说明:
		1》tyoe(功能,模块类型):
			包括auth,account,password,session。
			auth:	认证和授权;
			account:	与账号管理相关的非认证功能;
			password:	用户修改密码时使用;
			session:	用户获取到服务前后使用服务完成后要进行的一些附属性操作
			-type:	表示因为缺失而不能加载的模块将不记录到系统日志, 对于那些不总是安装在系统上的模块有用
			
		2》control:
			pam如何处理与该服务相关的pam的成功或失败情况?同一种功能的多个检查之间如何进行组合?有两种实现机制。
			1.使用一个关键词来定义:
				required(必填):	一票否决,表示本模块必须返回成功才能通过认证,但是如果该模块返回失败,失败结果也不会立即通知用户,而是要等到同一type中的所有模块全部执行完毕再将失败结果返回给应用程序。 必要条件
				requisite(必要):	一票否决,该模块必须返回成功才能通过认证,但是一旦该模块返回失败,将不再执行同一type 内的任何模块,而是直接将控制权返回给应用程序。必要条件
				sufficient(足够):	一票通过, 表明本模块返回成功则通过身份认证的要求,不必再执行同一type内的其它模块,但如果本模块返回失败可忽略。充分条件
				optional(可选项):	表明本模块是可选的,它的成功与否不会对身份认证起关键作用,其返回值一般被忽略
				include(包括):	使用其他配置文件中同样功能的相关定义来进行检查
			2.使用一到多组“return status=action”来定义;
				[status1=action1  status2=action2....]
				status:	指定此项检查的返回值,其可能的取值有多种。如success。
				action:	采取的操作,其可能的取值常用的有6种,如ok,done,die,ignore,bad,reset。
				ok 	模块通过,继续检查
				done  	模块通过,返回最后结果给应用
				bad  	结果失败,继续检查
				die  	结果失败,返回失败结果给应用
				ignore  	结果忽略,不影响最后结果
				reset  	忽略已经得到的结果
		3》module-path:
			模块路径,用来指明本模块对应的程序文件的路径名。
			相对路径
			绝对路径
			
		4》module-argument:
			模块参数,用来传递给该模块的参数。
			pam_unix.so:	
			nullok:	允许使用空密码;
			try_first_pass:	提示用户输入密码之前,首先检查此前栈中已经得到的密码;
			pam_env.so:	通过配置文件来为用户设定或撤销环境变量,/etc/security/pam_env.conf
			pam_shells.so:	检查用户使用的是否为合法shell,/etc/shells
			pam_limits.so:	资源限制,/etc/sercurity/limits.conf ;/etc/sercurity/limits.d/*

你可能感兴趣的:(#,Linux,CentOS,Ubuntu,等,linux,笔记,运维)