Whenever I upload a new file to my server, I have to
chown -R apache:apache /dir in order for it to be accessible.
Is there an easier way around this?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Most likely, what is actually needed for the files to be accessible is that their group is set to
apache. You can easily set it by default for new created files by running :
find /path/to/root/directory/of/website -type d -print0 | xargs -0 chmod g+s
This will set the
setgid flag on all sub-directories too. With this flag set, any new file created in there will inherit the group of its parent directory. (
-0 options are designed to handle correctly spaces in filenames)
Make sure ownerships of files are correct before running it. If unsure, you can fix it the same way :
find /path/to/root/directory/of/website -print0 | xargs -0 chown apache:apache
Here is what you could do with VSFTPD:
You can set the following 2 options in you
guest_enable, if enabled, makes sure all files are uploaded as user/group
Please note that this will only work for files uploaded via FTP. If you copy a file in Linux itself to your www directory, this will not adjust the permissions.
That's why, if you're also accessing that directory via the filesystem, it is best to use the
chmod g+s-method Levans suggested.
find /var/www/site/public_html -print0 | xargs -0 chown apache:apache find /var/www/site/public_html -type d -print0 | xargs -0 chmod g+s
If enabled, all non-anonymous logins are classed as "guest" logins. A guest login is remapped to the user specified in the guest_username setting.
See the boolean setting guest_enable for a description of what constitutes a guest login. This setting is the real username which guest users are mapped to.