Directory and File Permissions

Julian Matz
Julian Matz used Ask the Experts™

I've got a directory within a user's home directory called "logs". The permissions for this file are:

drwxrwxr-x (775)

"www-data" is the user running as the web server. Text files (logs) are automatically created in this directory by the server. The files created have the following permissions:

-rw-r--r-- (644)

My question is: is there any way to automatically make the created log files have the following permissions ? ( when the files are created ) :

-rw-rw-r-- (664)
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2005
Put into apache startup script
umask 0002 # instead default 0022. Also read 'help umask'

But in general case there's no way to force user/application to create files/dirs with predefined permissions.
nociSoftware Engineer
Distinguished Expert 2018

There is a possibility if you have ACL support in your kernel and on your file system, and it is enabled through mount.
 The default acl on a directory can define the settings needed for new files.
nociSoftware Engineer
Distinguished Expert 2018
BTW 'man setfacl' & 'man getfacl' should give you a starting point.
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Go to the home directory and look at your .profile file.
in here you can configure umask command.

1. cd /home/www-data
2. use ls-al  command to see all the files. In your home directory there files that begin . (dot), like .bash, .profile.
3. Use your favorite text edit to edit the .profile file.
4. Inside the .profile change the umask 022 to umask 002.

However, I will be carefull doing this because this change may cause problems later.

Julian MatzTechnical Support
Top Expert 2005



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial