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-- 1 linuxize users 12288 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). Numeric IDs for the user or group should be prefixed with the
+symbol to avoid conflicts with names. - FILE(s) - The name of one or more files, directories, or symlinks.
Key patterns:
USER- Sets the file owner to the given user. The group ownership is not changed.USER:- With GNUchown, a trailing colon changes the owner and sets the group 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 file1With GNU chown, a trailing colon with no group name sets the group to the user’s default login group:
chown linuxize: file1chown as the default. In our tests on Ubuntu 26.04 (uutils 0.8.0), chown USER: FILE changed the owner but left the group unchanged. If the group matters, name it explicitly with USER:GROUP. The GNU version is still installed as gnuchown and follows the documented behavior.How 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:www-data symlink1Most Linux distributions enable symlink protection by default. It applies to symlinks inside world-writable directories with the sticky bit set, such as /tmp. Inside these directories, the kernel blocks following a symlink unless its owner matches either the user running chown or the directory owner. A blocked operation prints a “cannot dereference ‘symlink1’: Permission denied” error and can fail even with sudo. 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:www-data /var/wwwWhen used recursively, chown does not follow symbolic links. Any symlinks inside the directory get the new ownership themselves, and the files they point to stay unchanged. You do not need to add -h.
The -H and -L options change 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.
Take Ownership as the Current User
A common use case is taking ownership of a file or directory as the current user. Use id -un and id -gn to get your user name and current group name without assuming they are the same:
sudo chown "$(id -un):$(id -gn)" file1
sudo chown -R "$(id -un):$(id -gn)" mydirThis is especially useful after copying files with sudo, extracting archives owned by root, or fixing permissions in a development directory.
Quick Reference
For a printable quick reference, see the chown cheatsheet .
| 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 (GNU chown) |
chown -R USER:GROUP DIR | Recursively change ownership |
chown -h USER FILE | Change symlink ownership (not target) |
chown --reference=REF FILE | Copy ownership from reference file |
chown +UID FILE | Use numeric UID (prefix + to avoid name conflicts) |
Troubleshooting
“cannot dereference ‘symlink’: Permission denied”
By default, chown tries to change the target of the symlink, not the symlink itself. Inside a sticky world-writable directory such as /tmp, symlink protection can block this even with sudo. Following the link is allowed when its owner matches the user running chown or the directory owner. 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 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page