Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My LAMP is setup to work as user:www-data and all files and folders are created with that permissions.

I have setup for crontab as user@ubuntu.

So i do crontab -e and use this command:

*/5 * * * * php /var/www/public/voto_m/artisan top >/dev/null 2>&1

Basically that command just creates cache file in specified place (no problems with that), but that cache file is created with user:user permissions not user:www-data permissions.

How can i make that it will by default create file with user:www-data permissions?
I can't go and chown each time file is recreated.


share|improve this question
up vote 19 down vote accepted

You can write your entry into the system crontab /etc/crontab, which takes an additional argument specifying the user to run as (usually root, but can be www-data).

Your line would become:

*/5 * * * * www-data php /var/www/public/voto_m/artisan top >/dev/null 2>&1

Or you can edit the crontab of user www-data with su:

sudo su -c "crontab -e" www-data
share|improve this answer
actually second option doesn't work on most versions of Ubuntu – IRus Apr 1 '15 at 6:47
The second option does work for me on 12.04LTS. Maybe it doen't on later versions? – mivk May 10 '15 at 13:31
second option is not working on 14.04 – dgoosens Jul 28 '15 at 21:41

You can also run crontab with the -u argument to edit a crontab for a specific user:

sudo crontab -u www-data -e
share|improve this answer
this works on 14.04 – dgoosens Jul 28 '15 at 21:41

To run a crontab as user www-data you can use the following command:

crontab -u www-data -e

Then you write a line, for example to run a php file every 15 minutes:

*/15  *  *  *  * php -f /path_to_cron/cron.php

When saving it, you will be asked by the editor:

File Name to Write: /tmp/crontab.HMpG7V 

Save it there, no worries. crontab -e opens a file in /tmp instead of the actual crontab so that it can check your new crontab for errors and prevent you from overwriting your actual crontab with those errors. If there are no errors, then your actual crontab will be updated. If crontab -e just wrote straight to your actual crontab, then you would risk blowing away your entire crontab.

To verify that your cronjob runs, you can check the cron logs. typically in /var/log/cron.log or executing the following command:

crontab -u www-data -l
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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