chown Command in Linux: Change File Ownership

By 

Updated on

9 min read

Linux Chown Command

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:

Terminal
ls -l filename.txt
output
-rw-r--r-- 12 linuxize users 12.0K Apr  8 20:51 filename.txt
              [------] [---]
                 |       |
                 |       +-----------> Group
                 +-------------------> Owner

chown Command Syntax

The basic syntax of the chown command is:

txt
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 to chgrp).
  • : 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:

txt
chown USER FILE

For example, the following command will change the ownership of a file named file1 to a new owner named linuxize:

Terminal
chown linuxize file1

To change the ownership of multiple files or directories, specify them as a space-separated list:

Terminal
chown linuxize file1 dir1

The numeric user ID (UID) can be used instead of the username:

Terminal
chown +1000 file2
Warning
If a numeric owner exists as a user name, the ownership will be transferred to the user name. To avoid this, prefix the ID with +.

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:

txt
chown USER:GROUP FILE

The following command will change the ownership of a file named file1 to a new owner named linuxize and group devs:

Terminal
chown linuxize:devs file1

If the group is omitted, Linux assigns the user’s default login group:

Terminal
chown linuxize: file1

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:

txt
chown :GROUP FILE

The following command will change the group of the file named file1 to www-data:

Terminal
chown :www-data file1

Alternatively, to change the group ownership of files, you can use the chgrp command.

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:

Terminal
chown www-data: symlink1

On 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_symlinks1 means enabled, 0 is disabled. We recommend keeping symlink protection enabled.

To change the ownership of the symlink itself, use the -h option:

Terminal
chown -h www-data symlink1

Recursively Changing Ownership

To recursively change ownership of all files and directories within a directory, use the -R (--recursive) option:

txt
chown -R USER:GROUP DIRECTORY

For 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:

Terminal
chown -R www-data: /var/www

If the directory contains symbolic links, pass the -h option:

Terminal
chown -hR www-data: /var/www

The -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.

txt
chown --reference=REF_FILE FILE

For example, the following command will assign the user and group ownership of file1 to file2:

Terminal
chown --reference=file1 file2

Common Use Cases

Here are the most common situations where you will use chown:

  • Web server directories — Set www-data:www-data ownership on /var/www so the web server process can read and write files. Combine with chmod for secure setups.
  • After file transfers or archive extractions — Files copied from another system or extracted from a tarball may retain the original UID. Use chown to 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 chown with chmod to 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

CommandDescription
chown USER FILEChange file owner
chown USER:GROUP FILEChange owner and group
chown :GROUP FILEChange group only
chown USER: FILEChange owner; set group to user’s login group
chown -R USER:GROUP DIRRecursively change ownership
chown -h USER FILEChange symlink ownership (not target)
chown -hR USER:GROUP DIRRecursively change, including symlinks
chown --reference=REF FILECopy ownership from reference file
chown +UID FILEUse 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.

Terminal
sudo chown $USER:$USER file1
sudo chown -R $USER:$USER mydir

This 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 .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

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