chown Command in Linux: Change File Ownership

The chown command in Linux allows you to change the user and/or group ownership of files, directories, and symbolic links. Knowing how to use chown is essential for managing access control, especially in multi-user environments.
In Linux, every file and directory has an owner and a group, along with permissions that define access rights for the file owner, the group members, and others.
This guide covers the chown command syntax, common options, practical examples, and best practices for secure usage.
What Is File Ownership in Linux?
Every file and directory in Linux has an owner and a group, and is assigned permission access rights for three different classes of users:
- Owner (the user who owns the file)
- Group (users in the file’s group)
- Others (everyone else)
File ownership can be viewed using the ls command:
ls -l filename.txt-rw-r--r-- 12 linuxize users 12.0K Apr 8 20:51 filename.txt
[------] [---]
| |
| +-----------> Group
+-------------------> Ownerchown Command Syntax
The basic syntax of the chown command is:
chown [OPTIONS] USER[:GROUP] FILE(s)Syntax Breakdown:
- USER - The user name or the user ID (UID) of the new owner.
- GROUP - The new group’s name or the group ID (GID).
- FILE(s) - The name of one or more files, directories, or symlinks. Numeric IDs should be prefixed with the
+symbol to avoid conflicts with usernames.
Key patterns:
USER- Sets the file owner to the given user. The group ownership is not changed.USER:- When a colon (:) follows the username, and the group name is not given, the user will become the owner of the files, and the file’s group ownership is changed to the user’s login group.USER:GROUP- If both the user and the group are specified (with no space between them), the user ownership of the files is changed to the given user, and the group ownership is changed to the given group.:GROUP- If the User is omitted and the group is prefixed with a colon (:), only the file’s group ownership is changed to the given group (equivalent tochgrp).:If only a colon (:) is given, without specifying the user and the group, no change is made.
Most common chown options:
-R- Apply to the directory and its contents recursively.-h- Change ownership of the symbolic links, not the referenced file.-v- Verbose output.--reference=REF_FILE- Copy ownership from reference file.
By default, chown does not produce any output on success and returns zero.
Who Can Use chown?
- Regular users can change the file group only if they own the file and only to a group they are a member of.
- Administrative users can change the ownership of all files.
Changing File Owner
To change the owner of a file, use the chown command followed by the user name of the new owner and the target file as an argument:
chown USER FILEFor example, the following command will change the ownership of a file named file1 to a new owner named linuxize:
chown linuxize file1To change the ownership of multiple files or directories, specify them as a space-separated list:
chown linuxize file1 dir1The numeric user ID (UID) can be used instead of the username:
chown +1000 file2+.Changing Owner and Group
To change both the owner and the group of a file, use the chown command followed by the new owner and group separated by a colon (:) with no intervening spaces and the target file as argument:
chown USER:GROUP FILEThe following command will change the ownership of a file named file1 to a new owner named linuxize and group devs:
chown linuxize:devs file1If the group is omitted, Linux assigns the user’s default login group:
chown linuxize: file1How to Change Group Ownership Only
To change only the group of a file, use the chown command followed by a colon (:) and the new group name (with no space between them) and the target file as an argument:
chown :GROUP FILEThe following command will change the group of the file named file1 to www-data:
chown :www-data file1Alternatively, to change the group ownership of files, you can use the chgrp
command.
Changing Symbolic Link Ownership
By default, the chown command changes the ownership of the files that the symlinks point to, not the symlinks
themselves.
For example, if you try to change the owner and the group of the symbolic link symlink1 that points to /var/www/file1, chown will change the ownership of the file or directory the symlink points to:
chown www-data: symlink1On most Linux distributions, symlinks are protected by default, so operating on the target file through a symlink may result in a “cannot dereference ‘symlink1’: Permission denied” error. This protection is controlled by /proc/sys/fs/protected_symlinks — 1 means enabled, 0 is disabled. We recommend keeping symlink protection enabled.
To change the ownership of the symlink itself, use the -h option:
chown -h www-data symlink1Recursively Changing Ownership
To recursively change ownership of all files and directories within a directory, use the -R (--recursive) option:
chown -R USER:GROUP DIRECTORYFor example, to change the ownership of all files and subdirectories under the /var/www directory to a new owner and group named www-data, you would run:
chown -R www-data: /var/wwwIf the directory contains symbolic links, pass the -h option:
chown -hR www-data: /var/wwwThe -H and -L options also affect how chown handles symbolic links during recursive traversal. -H causes chown to follow a symlink to a directory when that symlink is given as a command-line argument. -L causes it to follow every symlink to a directory that is encountered. Avoid these options in most cases — they can cause unintended ownership changes across the filesystem.
Using a Reference File
The --reference=ref_file option copies the owner and group from another file. If the reference file is a symbolic link, chown will use the ownership of the target file.
chown --reference=REF_FILE FILEFor example, the following command will assign the user and group ownership of file1 to file2:
chown --reference=file1 file2Common Use Cases
Here are the most common situations where you will use chown:
- Web server directories — Set
www-data:www-dataownership on/var/wwwso the web server process can read and write files. Combine withchmodfor secure setups. - After file transfers or archive extractions — Files copied from another system or extracted from a tarball may retain the original UID. Use
chownto reassign them to the correct local user. - Application deployments — Assign ownership of application files to a dedicated service user so the application runs with minimal privileges.
- Multi-user environments — Use
chownwithchmodto enforce clear boundaries between users sharing the same system.
Always verify ownership with ls -l before and after changes, especially when using -R. Avoid recursive operations on high-level directories such as / or /var.
Quick Reference
| Command | Description |
|---|---|
chown USER FILE | Change file owner |
chown USER:GROUP FILE | Change owner and group |
chown :GROUP FILE | Change group only |
chown USER: FILE | Change owner; set group to user’s login group |
chown -R USER:GROUP DIR | Recursively change ownership |
chown -h USER FILE | Change symlink ownership (not target) |
chown -hR USER:GROUP DIR | Recursively change, including symlinks |
chown --reference=REF FILE | Copy ownership from reference file |
chown +UID FILE | Use numeric UID (prefix + to avoid name conflicts) |
For a printable quick reference, see the chown cheatsheet .
Take Ownership as the Current User
A common use case is taking ownership of a file or directory as the currently logged-in user. Use the $USER variable to avoid hardcoding the user name.
sudo chown $USER:$USER file1
sudo chown -R $USER:$USER mydirThis is especially useful after copying files with sudo, extracting archives owned by root, or fixing permissions in a development directory.
Troubleshooting
“cannot dereference ‘symlink’: Permission denied”
By default, chown tries to change the target of the symlink, not the symlink itself. If symlink protection is enabled (the default on most systems), this fails. Use chown -h USER symlink to change the symlink’s own ownership instead.
“Operation not permitted”
Only root or a user with sudo can change file ownership to a different user. Run the command with sudo chown ....
“invalid user” or “invalid group”
The specified user or group does not exist on the system. Verify with id username or getent group groupname before running chown.
Recursive change affects the wrong files
Always run ls -la /path/to/dir to inspect the directory tree before using -R. A typo in the path or an unexpected symlink can cause ownership changes in unintended locations.
FAQ
What is the difference between chown and chmod?chown changes who owns a file (the user and group). chmod
changes the permission bits that control what the owner, group, and others can do with the file. Both are used together to manage access control.
How do I change the ownership of all files in a directory?
Use the -R flag: sudo chown -R USER:GROUP /path/to/dir. This applies the new ownership to the directory itself and everything inside it recursively.
Can a regular user change file ownership?
A regular user can change a file’s group to any group they belong to, as long as they own the file. Only root can transfer ownership to a different user.
How do I change only the group of a file?
Use chown :GROUP FILE or the chgrp
command, which is dedicated to group ownership changes.
What does the + prefix mean for numeric UIDs?
Normally, chown 1000 file could be interpreted as a username if a user named 1000 exists. Prefixing with + (chown +1000 file) forces chown to treat the value as a numeric UID, avoiding ambiguity.
Conclusion
The chown command is the standard way to transfer file and directory ownership in Linux. Use chown USER:GROUP FILE for a single file, add -R to apply changes recursively, and use -h when working with symbolic links. For permission bits rather than ownership, see the chmod guide
.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page