Chown Command in Linux (File Ownership)
Updated on
•6 min read

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- If only the user is specified, the specified user will become the owner of the given files. 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 doesn’t 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 group 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: symlink1Chances are that instead of changing the target ownership, you will get a “cannot dereference ‘symlink1’: Permission denied” error.
The error occurs because, by default, symlinks are protected on most Linux distributions, so you cannot operate on the target files. This option is specified in /proc/sys/fs/protected_symlinks. 1 means enabled, and 0 is disabled. We recommend not turning off symlink protection.
To change the group 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/wwwOther options that can be used when recursively changing the directory ownership are -H and -L.
If the argument to the chown command is a symbolic link pointing to a directory, the -H option will cause the command to traverse the symbolic link. -L tells chown to traverse each symbolic link to a directory that is encountered. Usually, you should not use these options because you might mess up your system or create a security risk.
Using a Reference File
The --reference=ref_file option copies ownership from another file (ref_file). If the reference file is a symbolic link, chown will use the user and group 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 and Best Practices
- Fixing permission issues after file transfers or archive extractions.
- Managing web server directories (/var/www). Combine with
chmodfor secure setups, e.g., web files:chown -R www-data:www-data /var/www + chmod -R 755 /var/www. - Assigning correct ownership for application files
- Maintaining secure multi-user environments
- Always grant minimal access needed.
- Always verify with
ls -lbefore and after changes. - Avoid recursive operations on high-level directories such as
/or/var. - Run as root/sudo only when necessary.
Conclusion
The Linux chown command is essential for managing files’ user and group ownership and access control. With chown, you can maintain system security, fix permission errors, and manage multi-user environments efficiently.
To learn more about the chown command, visit the chown man
page or type man chown in your terminal.
If you have any questions or feedback, feel free to leave a comment.


