chown: changing ownership of `...': Operation not permitted

Solution 1:

You have to be root to change the owner of files/directories.

sudo chown -R www-data /var/www/wordpress

If you're getting an error like Operation not permitted, just type:

sudo !!

at the prompt to execute the last command with root priviledges. This way, you don't have to retype chown -R www-data /var/www/wordpress.

Solution 2:

If you're not root, you'll need to become root to set these permissions:

sudo chown -R www-data /var/www/wordpress

Solution 3:

Besides being root, as others have pointed out, there is another more flexibile way to manage this privilige. You can also give files away via chown if your process / thread has the CAP_CHOWN Posix capability. For more info, and how to get that capability, see http://manpages.ubuntu.com/manpages/intrepid/man7/capabilities.7.html Unfortunately it doesn't yet seem to be possible for a process to gain specific capabilities like this based on attributes of an executable file. Either the process would have to be configured this way by another privileged process, or the executable would have to be fully setuid, and then give itself the capability before dropping root priviliges as a normal safety precaution.

A tip of the hat to Can't change owner (user or group) of directory which I have all rights on? - Super User