6

I recently changed the uid of my linux account (the reason for this change lies in the need to have a precise uid to access files on a mounted drive). Since then, I cannot access my crontab. After typing:

crontab -e

I get the error message:

crontabs/my_login/: fopen: Permission denied

I investigated the permissions associated to the file /usr/bin/crontab, it is:

-rwxr-xr-x 1 root my_login 35984 Feb  9  2013

However, if I look at the id of my_login, I get:

uid=11375(my_login) gid=1000(my_login) groups=1000(my_login),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),107(lpadmin),110(sambashare)

I can see something seems wrong with the gid but I am not sure what to do from this point...

9

Your permissions are incorrect for the crontab file. What it should be is like the following:

-rwxr-sr-x 1 root crontab 35984 Feb  9  2013 /usr/bin/crontab

To set your crontab to the above permissions, first change the ownership:

sudo chown root:crontab /usr/bin/crontab

Then set the permissions:

sudo chmod 2755 /usr/bin/crontab

That should set your crontab to the correct permissions to run.

EDIT:

Also, take a look at the /var/spool/cron/crontabs/ folder, you should see something similar to the following:

terrance@terrance-ubuntu:~$ sudo ls -al /var/spool/cron/crontabs/
total 16
drwx-wx--T 2 root     crontab 4096 Dec 17 22:08 .
drwxr-xr-x 3 root     root    4096 Dec  1 07:24 ..
-rw------- 1 root     crontab 1185 Dec 17 22:08 root
-rw------- 1 terrance crontab 1130 Dec 17 21:47 terrance

Pay attention to your username. If it doesn't have the proper ownership, change it by typing in the following:

sudo chown username:crontab /var/spool/cron/crontabs/username

And if permissions need to be set on that file:

sudo chmod 600 /var/spool/cron/crontabs/username

Hope this helps!

4
  • Thanks for your answer, however it did not fix my problem. I now have the permissions you mention : {-rwxr-sr-x 1 root crontab 35984 Feb 9 2013 crontab*} but I still get "permssion denied" after typing "crontab -e"
    – Alain
    Dec 18 '15 at 14:25
  • @Alain Edited my answer for the spool file permissions as well. Hope I can help you get this fixed. =)
    – Terrance
    Dec 18 '15 at 14:41
  • @Alain Not a problem. Glad it is working for you! =)
    – Terrance
    Dec 18 '15 at 14:46
  • 1
    I also had to run: sudo chmod g+w /var/spool/cron/crontabs; sudo chown root:crontab /var/spool/cron/crontabs - for some reason on DietPi /var/spool/cron/crontabs was owned by root:root.
    – Hackeron
    Jun 12 '17 at 12:39

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.