I have a folder in the home directory of my server named stock, as /home/stock. In this folder an ftp dump of data is being done by a third party application. The files added to these folders have a permission 644 and ownership as stock.users.

I also have a cron script which needs to access those files, uncompress it and then take further actions. My cron will run as web.users.

The problem is that my script is unable to access the files because of its permission set as 644. Is there any way to permanently set the folder's permission to 664. Executing the command chmod 664 on that folder, just changes the contents of the folder at that point of time but the files dumped in the future date still has permissions as 644.

Its also not feasible to change the permissions of the folder manually and setting a cron job to do the work doesn't seems a good option either.

Can anyone help ?

Thanks in advance.


It sounds from your description that the cron job just needs to read the files, which it should be able to do. Is the issue that you're trying to uncompress the files in place? Can you uncompress them to a temporary folder instead?

In order to modify the permissions of new files uploaded by FTP, you would need to change the umask of the FTP daemon process to 002. How to do that depends on the FTP server and Linux distribution.

| improve this answer | |

Make the directory owned by the web user, and group writable by the ftp user. Set the setuid bit on the directory, so that all files therein will be owned by the user running the cron job.

| improve this answer | |

Your script could do sudo chmod 664 given that you moddify /etc/sudoers to allow the execution of chmod by web.users without password.

You can do that adding this to /etc/sudoers

web.users localhost = (root) chmod


Be aware that this in the present way is insecure you have to addapt it to your needs and make sure its secure before doing something like this. One recommendation would be to have a special user for your script.

| improve this answer | |
  • This would be really dangerous from a security point of view - if the 'web' account were compromised (hit something unexpected in the subsequent processing) it would be able to run chmod on anything – Phil Miller Sep 2 '09 at 14:16

you can also add this chmod line in you script (run it as root OR (safier) the user who is used for the ftp transfers) :

chmod -R 664 /home/stock
tar -zxvf /home/stock/file.tar.gz for instance
+ treatments
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy