Crontab -e yields: /var/spool/cron/: mkstemp: Permission denied

cron

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

Best Answer

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.

Related Question