VMware ESXi and vSphere Cluster Management
Change File Ownership in Linux with chown and chgrp
Learn how Linux file ownership works and how to use chown and chgrp to change owners, groups, and ownership recursively.
Linux stores ownership information for every file and directory. The ownership consists of an owner, which is the user account associated with the filesystem object, and a group, which is the group account associated with it.
Ownership works together with permission modes. Permission modes define read, write, and execute access for the owner, the group, and other users. Ownership determines which user and group permission classes apply when Linux checks access.
Ownership may need to change after a file is created by the wrong account, transferred between users, copied from another system, or placed under the administration of a service or project team.
Inspecting ownership with ls -l
Use ls -l to display a file's permission string, owner, group, and name:
ls -l bobs_file.txt
A result might look like this:
-rw-r--r-- 1 alice developers 1200 Aug 18 10:30 bobs_file.txt
Change a file owner with chown
chown means “change owner.” It changes the owner of a file or directory and can optionally change its group at the same time.
The basic owner-only syntax is:
chown NEW_OWNER FILENAME
For example, assign bobs_file.txt to the user jwilliams:
chown jwilliams bobs_file.txt
When only a user name is supplied, this form changes the owner without intentionally changing the existing group. Verify the result afterward:
ls -l bobs_file.txt
Change both owner and group with chown
To set both ownership values, place the new user and group together with a colon between them:
chown NEW_OWNER:NEW_GROUP FILENAME
The colon separates the owner value from the group value. This command assigns bobs_file.txt to user jwilliams and group developers:
chown jwilliams:developers bobs_file.txt
Use this form when the file should belong to a particular user and also participate in a particular group's shared access.
Change only a file group
Sometimes the user owner is correct, but the file needs to belong to a different group. With chown, omit the owner and keep the colon before the group:
chown :developers bobs_file.txt
This changes the group to developers while leaving the current user owner unchanged.
chgrp is the dedicated command for changing a group. Its basic syntax is:
chgrp NEW_GROUP FILE_NAME
The equivalent group-only operation is:
chgrp developers bobs_file.txt
Recursive ownership changes
Recursive means that an operation applies to a directory and the files and subdirectories beneath it. The -R option enables recursive ownership changes.
Change the owner and group of a directory tree:
sudo chown -R jwilliams:developers /srv/project
Change only the group throughout a directory tree with chown:
sudo chown -R :developers /srv/project
Change only the group throughout a directory tree with chgrp:
sudo chgrp -R developers /srv/project
Linux ownership command forms
Authority, sudo, and account names
Changing ownership is an administrative operation. Ordinary users can usually change ownership only within limits imposed by the operating system. Assigning a file to another user commonly requires administrative privileges.
sudo is a command prefix that runs an authorized command with elevated privileges. Use it only when your account is permitted to do so and when the ownership change is appropriate:
sudo chown jwilliams:developers bobs_file.txt
The target user and group names must already exist. A misspelled or nonexistent account name causes the command to fail. Check the names using your system's user and group administration tools before retrying.
Troubleshooting ownership changes
“Operation not permitted”
This usually means the current account lacks authority to change the requested ownership. Confirm that the command and target are correct, then use sudo only when you have authorization and administrative responsibility.
“Invalid user” or “invalid group”
The specified user or group may not exist, or its name may be mistyped. Verify both names before running chown or chgrp again.
The group changed when only the owner was intended
An owner-and-group form was probably used accidentally:
chown jwilliams:developers bobs_file.txt
When only the owner should change, omit the colon and group:
chown jwilliams bobs_file.txt
Check the result with ls -l.
Too many files were changed
The -R option may have been used on a directory broader than intended. Review the target path carefully before recursive operations. Inspect representative files and directories with ls -l to validate the result.
Ownership appears unchanged
The wrong path may have been targeted, the command may have failed, or the result may not have been checked. Run ls -l against the exact target and confirm that the ownership command completed without an error.
Practical workflow
- Identify the exact file or directory that needs a change.
- Inspect its current owner and group with
ls -l. - Choose an owner-only, owner-and-group, or group-only command.
- Confirm that the target user and group exist.
- Use
sudoif the operation requires authorized administrative privileges. - For a directory tree, check the target path carefully before adding
-R. - Run
ls -lagain to verify the result.
Key points
- Every file and directory has an owning user and an owning group.
- Ownership is metadata; permission modes separately define read, write, and execute access.
- Use
chown USER FILEto change only the owner. - Use
chown USER:GROUP FILEto change both owner and group. - Use
chown :GROUP FILEorchgrp GROUP FILEto change only the group. - Use
-Rfor directory trees, but inspect the target carefully first. - Use
ls -lto check ownership and permission information.