问题

crontab -l 命令失败并出现以下错误。

# crontab -l
You (user) are not allowed to access to (crontab) because of pam configuration.

由于pam配置,不允许您(用户)访问(crontab)。

我们将在 cron 日志文件 /var/log/cron 中看到以下日志:

Sep 19 11:01:01 onitroad crond[125479]: (user) PAM ERROR (Permission denied)
Sep 19 11:01:01 onitroad crond[125479]: (user) FAILED to authorize user with PAM (Permission denied)
Sep 19 11:01:26 onitroad crontab[125631]: (user) PAM ERROR (Permission denied)

(user) PAM错误(权限被拒绝)
(user) 无法使用PAM授权用户(权限被拒绝)

日志文件 /var/log/secure 会有以下错误:

Sep 19 11:01:26 onitroad crontab: pam_access(crond:account): access denied for user `root' from `cron'
Sep 19 11:01:26 onitroad crontab: pam_unix(crond:account): expired password for user root (password aged)

pam_access(crond:account):拒绝从“cron”访问用户“root”
pam_unix(crond:account):root用户的密码过期(密码过期)

允许用户访问 /etc/security/access.conf 文件中的 cron 资源

  1. 另一个问题可能是不允许用户使用 /etc/security/access.conf 文件中的 cron 资源。
    在这种情况下,我们可以通过在文件 /etc/security/access.conf 中添加以下行来允许用户 cron 访问。
    通常这一行默认是散列的。
# vi /etc/security/access.conf
# User "root" should be allowed to get access via cron .. tty5 tty6.
+ : user : cron crond :0 tty1 tty2 tty3 tty4 tty5 tty6
  1. 还要检查用户被拒绝使用 cron 的任何条目。
    在这种情况下,我们必须从文件 /etc/security/access.conf 中删除该条目。
    拒绝对用户进行 cron 访问的示例条目如下所示:
# vi /etc/security/access.conf
# Deny all other users access by any means.
-: ALL : ALL

或者

# vi /etc/security/access.conf
# deny user "user" access to cron
- : user : cron crond :0
更多: zhilu jiaocheng

检查过期的用户密码

1.首先,使用chage命令检查用户密码是否过期。

# chage -l user
Last password change                                    : Jan 19, 2017
Password expires                                        : Sep 02, 2017        ### password has expired
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 45
Number of days of warning before password expires       : 7

从上面的输出我们可以说密码已于 2017 年 9 月 2 日过期。
如果以密码已过期的用户身份运行,Crontab 命令将失败。
如果该用户的密码已过期,PAM 将不允许以用户身份运行 cronjob。

  1. 如果密码已过期,则需要为用户设置新密码以允许用户运行 cronjobs。
    要为用户设置密码,请以 root 身份运行以下命令:
# passwd user
  1. 如果环境允许,我们还可以为该特定用户设置密码永不过期。

解决方案

此错误可能有 2 个原因:

  1. 用户密码过期
  2. 用户不允许访问 /etc/security/access.conf 文件中的 cron。
crontab 报错You (user) are not allowed to access to (crontab) because of pam configuration.

检查确认

如果我们应用了上述任何一种解决方案,我们可以以用户身份运行命令 crontab -l 或者 crontab -e 来验证 cron 访问。

日期:2020-09-17 00:14:15 来源:oir作者:oir