I want all the files in /var/www
directory be owned by nginx.devel.
I have performed chmod
once and update these files using rsync
.
But if I create a new file and then rsync
it, it will be owned by user.user and I need to run chmod
with sudo
privileges on it.
You can't. Well, not automatically anyway. You can, however, enforce group permissions, which with careful planning and an appropriate umask, can solve most permissions problems. If you set the setgid bit on the
/var/www
directory it will ensure that any new files created under it are owned by thedevel
group.Note that depending on which flags you use,
rsync
may override this behavior and replicate the ownership of the source files.To set the setgid bit:
Demo of the behavior:
The effect is recursive as well; any new directories created after you set the setgid bit will also have the setgid bit set.
An alternative to this approach, of course, would be a cron job that runs every minute and fixes the permissions on the files under
/var/www/
.