How to Change File Ownership and Groups in Linux
Learn how to inspect and change Linux file ownership with chown and chgrp, including owner, group, recursive changes, verification, and troubleshooting.
Linux assigns every file and directory an owner user and an owning group. These identities are part of the filesystem's access-control system. You can change them from the command line with chown and chgrp.
This lesson assumes familiarity with cd, ls, shell arguments, Linux users and groups, sudo, and basic file permissions. For related Linux topics, see Linux command-line guides.
Linux File Ownership and Permissions
Ownership is the user and group identity associated with a filesystem object. The owner is the user account recorded for the object, while the group is the group account recorded for it.
Ownership is different from the permission mode. The permission mode contains read, write, and execute bits for the owner, group, and other users. Ownership determines which accounts those permission categories refer to.
- The owner permissions apply to the recorded owner user.
- The group permissions apply to users who belong to the recorded group.
- The other permissions apply to users who are neither the owner nor members of the group.
Changing ownership can therefore change who receives a file's owner or group permissions. It is also an important administrative task for shared projects, services, web content, backups, and application data.
Inspect Current Ownership with ls -l
Before changing ownership, inspect the exact target:
ls -l bobs_file.txt
A typical long-format listing might look like this:
-rw-r----- 1 bob developers 1280 Aug 17 10:30 bobs_file.txt
| Field | Meaning | Example value |
|---|---|---|
| Permission string | File type and permissions for owner, group, and others | -rw-r----- |
| Owner user | User account that owns the object | bob |
| Owner group | Group account associated with the object | developers |
| File name | Name of the directory entry being listed | bobs_file.txt |
In this output, the owner and group are the fields after the link count and before the size. The permission string is separate: changing ownership does not directly change the read, write, or execute bits.
Change a File Owner with chown
chown means “change owner.” Its basic owner-only form is:
sudo chown NEW_OWNER FILE
For example:
sudo chown jwilliams bobs_file.txt
This changes the user owner to jwilliams while leaving the existing group unchanged. Changing ownership commonly requires root privileges. Root is the administrative user that can generally change ownership of arbitrary files. sudo runs an authorized command with elevated privileges.
Verify the result by listing the same path:
ls -l bobs_file.txt
Check that the owner field now contains jwilliams. The command's exit status can also indicate whether it succeeded; a zero status normally indicates success.
Change Both Owner and Group with chown
Use the OWNER:GROUP form to assign both identities in one command:
sudo chown jwilliams:developers bobs_file.txt
The colon separates the valid user name from the valid group name. This command sets the owner to jwilliams and the group to developers.
Confirm both fields:
ls -l bobs_file.txt
Do not confuse the colon with part of either account name. Use account names that actually exist on the system.
Change Only the Group with chown
To keep the current owner and replace only the group, omit the owner before the colon:
sudo chown :developers bobs_file.txt
The :GROUP form changes the group to developers without changing the user owner. This differs from OWNER:GROUP, which changes both values.
Change a Group with chgrp
chgrp is the dedicated command for changing group ownership. Its syntax is:
sudo chgrp NEW_GROUP FILE
For example:
sudo chgrp developers bobs_file.txt
This changes only the group and leaves the owner unchanged. chgrp is often clearer when the task is specifically a group change. The equivalent chown :developers bobs_file.txt is useful when you are already using chown syntax.
Commands for Changing Linux Ownership
| Goal | Command pattern | Example | What changes |
|---|---|---|---|
Change owner only with chown | chown NEW_OWNER FILE | sudo chown jwilliams bobs_file.txt | User owner only |
Change owner and group with chown | chown NEW_OWNER:NEW_GROUP FILE | sudo chown jwilliams:developers bobs_file.txt | User owner and group |
Change group only using chown :GROUP | chown :NEW_GROUP FILE | sudo chown :developers bobs_file.txt | Group only |
Change group only with chgrp | chgrp NEW_GROUP FILE | sudo chgrp developers bobs_file.txt | Group only |
Apply changes recursively with -R | chown -R NEW_OWNER:NEW_GROUP DIRECTORY | sudo chown -R jwilliams:developers /srv/project | Selected directory and its contents |
Apply Ownership Changes Recursively
An operation is recursive when it applies to a directory and everything beneath it. The -R option makes chown or chgrp process the selected directory, its files, and nested subdirectories.
sudo chown -R jwilliams:developers /srv/project
This sets the owner and group throughout the /srv/project directory tree. To change only groups recursively, use:
sudo chgrp -R developers /srv/project
Inspect the directory itself and its immediate contents after a recursive change:
ls -ld /srv/project && ls -l /srv/project
The -d option makes ls display the directory entry rather than listing only its contents. The second command shows the immediate entries inside it.
Confirm Users and Groups Before Changing Ownership
Check that the target user exists:
id jwilliams
id displays the user's numeric identity and group memberships. It also helps distinguish a misspelled user name from a valid one.
Check that a group exists:
getent group developers
getent group checks configured name-service sources, which can include local and directory-based accounts. If either command cannot find the requested identity, correct the name or create the account or group through the appropriate administrative process.
Use Safe Paths and Shell Quoting
Use an explicit path so that the command targets the intended object. An absolute path such as /srv/project removes ambiguity about the current directory. You can inspect the current directory with ls before changing anything.
Quote file names containing spaces or shell-special characters:
sudo chown jwilliams "Bob's File.txt"
Without quoting, the shell would treat the space as an argument separator. Quoting also prevents the shell from interpreting many special characters as syntax.
Troubleshooting Ownership Changes
“Operation not permitted” or “Permission denied”
The current account lacks authority to change the target's ownership. Use sudo when you are authorized, or ask the appropriate administrator. Ordinary users generally cannot assign arbitrary files to arbitrary owners.
“Invalid user” or “invalid group”
The account name may be misspelled or may not exist. Check it with id USER or getent group GROUP, then rerun the command with valid names.
“No such file or directory”
The path may be wrong, the current directory may not be what you expect, or a name containing spaces may not have been quoted. Confirm the path with ls, use an absolute path when useful, and quote filenames such as "Bob's File.txt".
A recursive command changed too many files
The -R option may have been applied to an overly broad or incorrect directory. Before repeating the operation, inspect the target with:
ls -ld /srv/project
Use the narrowest correct directory path and avoid recursive changes when only one file needs modification.
Ownership appears unchanged
The command may have targeted a different path, failed, or the result may not have been checked. Run ls -l on the exact target and review the command's exit status. For a directory, use ls -ld DIRECTORY to inspect the directory itself.
Practical Workflow
- Confirm the intended path with
lsor an absolute path. - Inspect current ownership with
ls -l FILEorls -ld DIRECTORY. - Confirm the target user with
id USERand group withgetent group GROUP. - Choose
chownfor an owner change,chown :GROUPorchgrpfor a group-only change, and-Ronly for an intentionally complete directory tree. - Use
sudowhen authorized and required. - Run
ls -lagain and verify the exact owner and group fields.
Exam-Relevant Notes
chown NEW_OWNER FILEchanges the user owner.chown OWNER:GROUP FILEchanges both the user owner and group.chown :GROUP FILEchanges only the group and retains the user owner.chgrp GROUP FILEchanges only the group.-Rmeans recursive: the operation includes the directory and all contents beneath it.ls -ldisplays the permission string, owner, group, and file name needed to verify a change.- Ownership changes and permission-mode changes are separate operations;
chowndoes not replacechmod.