用户 x 不能使用这个程序 (crontab)

Ada*_*lik 12 cron ubuntu

Ubuntu 14.04

我不明白我在为服务(无登录)帐户(名为curator)设置 crontab 时看到的行为。

当我以 root 身份登录时,这就是我得到的:

# crontab -u curator -l
The user curator cannot use this program (crontab)
Run Code Online (Sandbox Code Playgroud)

但是,当我切换到用户的帐户时,它工作正常:

# su -s /bin/bash curator
curator@host$ crontab -l
no crontab for curator
Run Code Online (Sandbox Code Playgroud)

有一个空/etc/cron.allow文件,/etc/cron.deny系统上没有文件。根据man crontab

如果 /etc/cron.allow 文件存在,那么您必须在其中列出(每行一个用户)才能允许使用此命令。如果 /etc/cron.allow 文件不存在但 /etc/cron.deny 文件确实存在,则您不能被列在 /etc/cron.deny 文件中才能使用此命令。

我在运行第一个命令时理解错误,但是为什么crontab当我明确切换到用户帐户时它允许我运行?

添加用户/etc/cron.allow使这两个命令都能正常工作。

小智 14

我检查了 crontab 源,发现如果用户无法打开/etc/cron.allow(例如在 之后chmod 0 /etc/cron.allow),crontab 认为用户可以使用它(好像cron.allow不存在)。

但是 root 可以读取任何文件,因此 crontab 检查代码按预期工作。因此,我建议您首先检查 上的权限/etc/cron.allow,也许还检查SELinux/AppArmor 审核日志。