Changing ownership with chown

Need to CHange the OWNer of a file or directory?

chown [new owner] [file or directory]

If, for example, I wanted to change the owner of /var/www/vhosts/my_website/tmp to “root” I’d run this:

chown root /var/www/vhosts/my_website/tmp

If you want to apply the ownership change recursively — that is, to all subdirectories and/or files within — add the -R flag:

chown -R root /var/www/vhosts/my_website/tmp

If you get an Operation not permitted error, you don’t have sufficient permissions to chown that particular resource. Take a moment and make sure you are actually doing what you think you’re doing.

Go ahead — I’ll wait.

Assuming you are, run the command again with sudo to grant yourself the necessary permissions:

sudo chown -R root /var/www/vhosts/my_website/tmp