Linux Command: chown
Change file owner and group
chown (change owner) changes the user and/or group ownership of files and directories. File ownership determines which permission set (user, group, other) applies to each user accessing the file. chown requires root privileges (or ownership of the file on some systems). It can change the owner, the group, or both simultaneously with the user:group syntax. chown is essential for web server setup (changing files to www-data), application deployment, and fixing ownership after file transfers or extractions.
Syntax
chown [OPTION]... OWNER[:GROUP] FILE...Key Options
user:groupโ Change both owner and groupuserโ Change owner only:groupโ Change group only-Rโ Recursive--referenceโ Copy ownership from another file-vโ Verbose โ show changes
Examples
Change owner and group
sudo chown www-data:www-data /var/www/html/Recursive ownership
sudo chown -R deploy:deploy /opt/myapp/Change group only
sudo chown :developers /shared/project/Pro Tips
- Only root can change file ownership. Use sudo chown. Regular users can only change the group to a group they belong to.
- chown user:group file changes both at once. This is more efficient than separate chown and chgrp commands.
- chown 1000:33 file works with numeric UIDs and GIDs. Useful when username does not exist on the current system.
Learn more: Full chown reference โ