Unix – To copy files each minute at /var/www without sudo

cpsudounix

How can you copy a folder to /var/www without sudo?

My folder codes has the following permissions at /var/www

4 drwxr-xr-x 8 root root 4096 2009-08-09 03:01 codes

I can only sudo cp -r ~/Dropbox/codes/ /var/www to copy the files.
I cannot copy them without sudo.

Best Answer

Owning /var/www yourself might conflict with other options on your system. On my Debian system I would do this

sudo addgroup www
sudo adduser nr www   # add myself to the www group
sudo chgrp -R www /var/www  # make files in the group
find /var/www -type f -exec chmod g+w '{}' ';'  # make each file group writable
find /var/www -type d -exec chmod g+ws '{}' ';' # make each directory group writable and sticky

If the directory is group writable and sticky, all files created in /var/www will be writable by anyone in the www group, no matter who or what creates them there. (Caveat: they have to be created by "normal" means; cp -a can circumvent the group sticky bit.)

Because Unix is insanely stupid about group membership, for your membership to be honored you will have to log in again, e.g., ssh localhost or log out and log back in. A nuisance.