TechEarl

How to Change File Owner and Group on Linux (chown)

Change ownership with chown user:group, do it recursively, change only the group, and why changing an owner needs root while chgrp sometimes does not.

Ishan Karunaratne⏱️ 3 min readUpdated
Share thisCopied
Change file ownership on Linux with chown user:group, recursively with -R, and the difference between chown and chgrp.

Permissions decide what the owner and group may do; chown decides who the owner and group are. Set both at once with user:group, which is a root task:

bash
sudo chown deploy:developers report.txt
Root terminal showing ls -l of a file owned by techearl, then chown deploy:developers on it, then ls -l confirming the owner and group changed.
chown user:group sets both the owner and the group in one go. ls -l confirms the change.

The forms

bash
sudo chown deploy file              # owner only
sudo chown deploy:developers file   # owner AND group
sudo chown :developers file         # group only (leading colon)
sudo chown deploy: file             # owner, and set group to deploy's primary group

Recursively, for a whole tree

bash
sudo chown -R deploy:developers /srv/app

-R walks the directory. This is the standard fix after deploying files as the wrong user, or after a git clone/tar as root left everything owned by root. It pairs with recursive chmod when both owner and mode are wrong.

chown vs chgrp, and who is allowed

  • Changing the owner always needs root. A normal user cannot give a file away to someone else (that would let people dodge quotas and plant files).
  • Changing only the group can be done by the file's owner with chgrp, but only to a group they themselves belong to:
bash
chgrp developers report.txt         # owner can do this if they're in developers

So chgrp (or chown :group) is sometimes available without sudo; reassigning the owner never is.

The classic case: a root-owned file you cannot edit

You ran something with sudo and now a file in your home is owned by root and you cannot write it. Hand it back:

bash
sudo chown $USER:$USER ~/.config/app/settings.json

This is the same root cause behind sudo ssh-keygen making an unusable key: elevation created root-owned files in your space.

FAQ

See also

Sources

Authoritative references this article was fact-checked against.

TagsLinuxchownchgrpOwnershipPermissions

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Tech Architect · Software Engineer · AI/DevOps

Tech architect and software engineer with 20+ years building software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Currently Chief Technology Officer at a healthcare tech startup, which is where most of these field notes come from.

Keep reading

Related posts

How to List Users and Groups on Linux

List every user and group from /etc/passwd and /etc/group with getent, tell human accounts from system ones by UID, and see which groups a user belongs to.