Recursively changing permissions

There are times when your website's filesystem permissions get screwed. There's no other way to put it -- some directories are not writeable, some are not ... ARGH! The worst part is that you need to apply different permissions on files and directories, to prevent security issues.

Here are two simple one-liners that do exactly that:

For files, you only need to make them world-readable, and writeable by your user/group

# find /var/www/mysite-dir -type f -exec chmod 664 {} \;

The above command will recursively apply read/write permissions to all files for the owner and group, and only read for everyone else.

For directories, you also need to include the execute bit, otherwise you won't be able to enter into the directory:

# find /var/www/mysite-dir -type d -exec chmod 775 {} \;

The above command will recursively apply read/write/execute permissions to all directories for the owner and group, and only the read and execute for everyone else.

Finally, if you collaborate with others, it may be beneficial to make group permissiosn sticky so that when they create files they don't have them all to themselves:

# find /var/www/mysite-dir -type d -exec chmod g+s {} \;

The above command will make it so that new files maintain the parent folder's group permissions (ie writeable from group).