3

I'm trying to set up a cron job under my user. I run crontab -e, make my edits, and try to save and exit. I receive the following error message /var/spool/cron/: mkstemp: Permission denied.

Relevant output from ls -al /var/spool/cron/crontabs

drwxr-xr-x 2 root crontab 4096 Nov  4 10:09 .
drwxr-xr-x 5 root root    4096 Nov 19  2014 ..
-rw-rw-rw- 1 greg crontab   91 Nov  4 11:04 greg
-rw------- 1 root crontab 1231 Oct 29 16:18 root

I can directly edit the greg file and save that but I still can't seem to get the job to run, even if I restart cron after updating it. What do I need to do to fix this problem?

The output from ls -lha $(which crontab) is:

-rwxr-sr-x 1 root crontab 36K Feb  8  2013 /usr/bin/crontab

The output from groups greg is:

greg : greg adm sudo crontab lpadmin sambashare
  • What does ls -lha $(which crontab) say? crontab should be setuid root becaue it will create temporary files in /var/spool/cron. – Ulrich Schwarz Nov 4 '15 at 19:39
  • Does user greg belong to group cron? – eyoung100 Nov 4 '15 at 19:39
  • @eyoung100 Yes, greg is part of the crontab group. I'm assuming thats what you meant? – Gregory Arenius Nov 4 '15 at 19:49
  • Have you logged out and back in since you added your user? – eyoung100 Nov 4 '15 at 19:50
  • @UlrichSchwarz I think have posted the output of that ls command to the question. I think it is set to root. – Gregory Arenius Nov 4 '15 at 19:50
7

This will fix your immediate problem:

chmod u=rwx,g=wx,o=t /var/spool/cron/crontabs

But, if you can download packages, a more robust way to fix this is to use apt-get to reinstall the appropriate package:

root@ubuntu# dpkg-query -S /var/spool/cron/crontabs
cron: /var/spool/cron/crontabs
root@ubuntu# apt-get install --reinstall cron

after first making sure any local changes you've made to /etc/init/cron.conf, /etc/default/cron, etc. are copied somewhere and then reapplied.

1

The solution mentioned by Mark Plotnick didn't work for me, however after adding my user to the crontab group it worked:

sudo adduser myname crontab

You'll need to logout and login again for this change to be applied.

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.