chown Command Cheat Sheet
chown (change owner) is used to change the file owner and group. It is essential for managing file access controls in multi-user environments.
Synopsis
chown [OPTION]... [OWNER][:[GROUP]] FILE...
chown [OPTION]... --reference=RFILE FILE...
Description
chown changes the user and/or group ownership of each given file. If only an owner (a user name or numeric user ID) is given, that user is made the owner of each given file, and the file's group is not changed. If the owner is followed by a colon and a group name (or numeric group ID), with no spaces between them, the group ownership of the files is changed as well.
⚠️ Note: Only the root user (super-user) can change the owner of a file to someone else.
Basic Syntax Combinations
| Command | Action |
|---|---|
chown user file |
Change owner to user. Group unchanged. |
chown user:group file |
Change owner to user and group to group. |
chown user: file |
Change owner to user and group to login group of user. |
chown :group file |
Change group to group. Owner unchanged. |
Examples
Change Owner Only
sudo chown alice presentation.pptx
Change Owner and Group
sudo chown bob:developers logic.js
Change Group Only
Equivalent to using chgrp.
sudo chown :staff report.txt
Set Group to User's Login Group
If alice belongs to group alice:
sudo chown alice: file.txt
# Owner becomes alice, Group becomes alice
Recursive Ownership
Use -R to operate on files and directories recursively.
sudo chown -R www-data:www-data /var/www/html
Changes ownership of /var/www/html and everything inside it.
Reference Mode
Change ownership to match another file.
sudo chown --reference=template.txt newfile.txt
If template.txt is owned by root:root, newfile.txt will also be owned by root:root.
Symlink Handling
By default, chown changes the ownership of the target of a symbolic link, not the link itself.
Change Link Ownership (-h)
To change the ownership of the symbolic link itself (on systems that support it, like Linux):
sudo chown -h user:group symlink
Recursive Symlink Traversal
When using -R:
- -H: Traverse command-line symlinks to directories.
- -L: Traverse all symlinks to directories.
- -P: Do not traverse any symlinks (Default).
# Don't follow symlinks inside directory (Safest)
sudo chown -R -P user:group /path/to/dir
Reporting Changes
Verbose (-v)
Reports diagnostic for every file processed.
sudo chown -v user file
# changed ownership of 'file' from root to user
Changes Only (-c)
Reports only when a change is actually made.
sudo chown -c user file
Silent (-f)
Suppress most error messages (like "Operation not permitted").
sudo chown -f user file
Practical Use Cases
Fix "Permission Denied" in Docker Volumes
Often used when a container creates files as root.
sudo chown -R $USER:$USER ./data
Taking Ownership of a Directory
After copying files from another system or USB drive:
sudo chown -R $(id -u):$(id -g) ~/restored_backup
Standard Web Server Permissions
# Owner is your user (for editing), Group is web server (for reading)
sudo chown -R ubuntu:www-data /var/www/site
Common Pitfalls
Accidental Root Takeover
Running sudo chown -R root:root /home/user will break the user's ability to login or use their desktop.
Colon vs Dot
Historically, chown user.group was allowed. It is still supported but deprecated because it causes ambiguity if a username contains a dot (e.g., firstname.lastname).
Always use the colon (:) separator.
Exit Status
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Error (missing file, invalid user/group, permission denied) |