0

I encounter a strange Linux cron job permission error on Amazon Linux and can't found related information on the web.

1. First I create a cron job with a regular user
[newuser@node1 home]$ crontab -e
no crontab for newuser - using an empty one
crontab: installing new crontab

2. Then I try to read the cron job file, permission deny
[newuser@node1 home]$ cat /var/spool/cron/newuser
cat: /var/spool/cron/newuser: Permission denied

It is strange as "newuser" is the owner of that file, why "permission denied" ?

    Login as root.
    [root@node1 home]# cd /var/spool/cron
    [root@node1 cron]# ls -l

    -rw------- 1 newuser  newuser  47 Aug  3 08:28 newuser

    [root@node1 cron]# cat /var/spool/cron/newuser
    1 1 1 * * /usr/bin/php /tmp/scheduleJob.php

[root@node1 spool]# ll -d /var/spool/cron
drwx------ 2 root root 4096 Aug  3 08:28 /var/spool/cron
1

On Linux systems to access a file you also need to have access to traverse all the directories in the path (execute bit in UNIX permissions). In your case /var/spool/cron permissions are set to rwx------ and owner is root, therefore you cannot traverse into the directory as other user than root and get Permission denied error when trying to access contents within.

0

Great Thread, it pointed me in the correct direction. I was fixing a VM that had been cloned and All the GID and UID's were messed up.

Here is what I did on RedHat 5 to fix mine:

[root@pb-qad /]# find . -name cron.allow
./etc/cron.d/cron.allow
--ADDED mfg user

[root@pb-qad ~]# chown root:crontab /usr/bin/crontab
chown: `root:crontab': invalid group

[root@pb-qad ~]# groupadd crontab
[root@pb-qad ~]# groupmod crontab --gid 65535

[root@pb-qad ~]# chown root:crontab /usr/bin/crontab
You have new mail in /var/spool/mail/root

[root@pb-qad ~]# chmod g+s /usr/bin/crontab
[root@pb-qad ~]# ls -al /usr/bin/crontab
-rwxr-sr-x 1 root crontab 315432 Dec 11  2009 /usr/bin/crontab

[root@pb-qad ~]# usermod -a -G crontab mfg
[root@pb-qad ~]# groupmod -g 65535 crontab
groupmod: 65535 is not a unique GID

[root@pb-qad ~]# cd /var/spool/

FINAL FIX

[root@pb-qad spool]# chown root:crontab cron
[root@pb-qad spool]# ll -al
total 476
drwxr-xr-x 16 root   root      4096 Oct  1  2009 .
drwxr-xr-x 26 root   root      4096 Mar 21 15:49 ..
drwxr-xr-x  2 root   root      4096 Dec  5  2008 anacron
drwx------  3 daemon qad       4096 Nov 16  2009 at
drwxrwxrwx  2 smmsp  smmsp    69632 Apr 25 09:25 clientmqueue
drwx-wx--T  2 root   crontab   4096 Mar 21 15:49 cron

Now, Cron works as mfg user!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.