There are many situations when you may need to change the ownership of files, especially if you are operating a virtual private server or dedicated server. For example, you may install something for a website as root but then need to set ownership of the file to the local user. Linux has a convenient command called “chown” that does exactly that. The word “chown” is short for “change the owner”.
Let’s suppose that you have a file called “testfile” owned by root. You want to change ownership to user1. Simply enter this command:
chown user1:users testfile
In this case, “user1” is the user’s name and “users” is its user group.
If you want to change the ownership of all the files in a directory, you would add the “-R” tag to make the operation recursive.
chown -R user1:users test-directory
For more information about chown, enter this command: man chown
.
Photo Source: SXC