1

There are multiple options - with cron - to start your script at a specific time, but is one more secure over the other?

My question is simple:

What's the difference between adding scripts in the /etc/cron.daily/ or editing in your script in crontab(-e)?

What I'm worried about is that other users are able to see the content. I want to make sure that nobody but root can view the crontab, whether it be in the /etc/cron.daily/ or the user's crontab.

Are other users able to see what's in /etc/cron.daily/ or the crontab, which you can see with crontab -l?

I'm always logged as root in a particular server. I just need to know who/what/when about crons, so that I can choose wisely when implementinig cron jobs.

I'm using CentOS 6.6.

2

The system-wide scripts in /etc/cron* are world-readable by default. For example, on my Arch:

$ ls -ld /etc/cron*
drwxr-xr-x 2 root root 4096 May 31  2015 /etc/cron.d
drwxr-xr-x 2 root root 4096 May 31  2015 /etc/cron.daily
-rw-r--r-- 1 root root   74 May 31  2015 /etc/cron.deny
drwxr-xr-x 2 root root 4096 May 31  2015 /etc/cron.hourly
drwxr-xr-x 2 root root 4096 May 31  2015 /etc/cron.monthly
drwxr-xr-x 2 root root 4096 May 31  2015 /etc/cron.weekly

And:

$ ls -l /etc/cron.d/0hourly 
-rw-r--r-- 1 root root 128 May 31  2015 /etc/cron.d/0hourly

User-specific cron files are in /var/spool/cron by default and they, at least on my system, are not world-readable:

$ ls -l /var/spool/cron/
total 8
-rw------- 1 root   root   20 Feb 23 16:34 root
-rw------- 1 terdon terdon 22 Feb 23 16:32 terdon

So, the "safest" way would be to use the user's crontab, the one you get with crontab -e. Normal users can't read that:

$ cat /var/spool/cron/root 
cat: /var/spool/cron/root: Permission denied

I suggest you check and make sure this is also the case on your CentOS first though, I don't have access to a CentOS machine at the moment.

0

On /etc/cron.daily/ you have the user (as first field), so it can run cronjob of any user. AFAIK it is the only difference.

The /etc/cron.daily/ has the advantage of backups and deployment. The files in /var/spool/cron/crontabs/ (used by cronttab -e are more prone to be overwritten.

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.