chmod vs chown vs chgrp: Differences with Examples

chmod vs chown vs chgrp: what each command changes, who can run it, octal and symbolic modes, recursive tips, setgid team folders and common fixes.

Aug 1, 2025 - 17:41
Nov 5, 2026 - 18:21
 0  305
TOPICDevOps BasicsPractical guide
chmod vs chown vs chgrp: Differences with Examples

chmod changes what a file's owner, group and everyone else may do with it (read, write, execute). chown changes who owns the file, and can change the owning group at the same time. chgrp changes only the owning group. Use chown or chgrp to put the right people in place, then chmod to set what they can do.

This guide is part of our Linux basics series. If you are new to the command line, start with RHEL 10 basic commands every beginner should know, then come back here for the ownership and permission commands that cause the most "Permission denied" tickets on real servers.

Key takeaways

  • Every file has three things these commands touch: an owner (a user), a group, and a set of mode bits. chown edits the first two, chgrp edits the second, chmod edits the third.
  • Only root (or a process with the CAP_CHOWN capability) can give a file to another user. A regular owner can change a file's group with chgrp, but only to a group they belong to.
  • chmod accepts octal modes such as 640 and symbolic modes such as g+w,o-rwx. Symbolic mode is safer when you want to change one bit and leave the rest alone.
  • chown user:group does the job of chgrp and chown in one step, so many admins rarely type chgrp at all.
  • On Linux, changing the owner or group of an executable clears its setuid and setgid bits. Re-apply them with chmod if you really need them.
  • Recursive changes (-R) are where most mistakes happen. Use capital X with chmod so directories stay searchable without making every file executable.

How Linux decides who can access a file

When a process opens a file, the kernel compares the process's user ID and group IDs with the file's owner and group. If the process runs as the owner, the owner bits apply. If not, and the process is in the file's group, the group bits apply. Otherwise the "other" bits apply. Only one set is used, checked in that order. That is why a file owned by you with mode 077 locks you out even though everyone else can read it.

You can see all three pieces with ls -l:

$ ls -l report.csv
-rw-r----- 1 priya analytics 4096 Nov  7 10:12 report.csv

Here priya is the owner, analytics is the group, and rw-r----- is the mode: the owner can read and write, the group can read, and others get nothing. chown would change priya, chgrp would change analytics, and chmod would change rw-r-----. For a deeper look at what each permission bit means, see how to set and modify file permissions in Linux.

chmod vs chown vs chgrp at a glance

Questionchmodchownchgrp
What it changesMode bits (rwx for user, group, other, plus setuid, setgid, sticky)Owner, and optionally groupGroup only
Name stands forChange modeChange ownerChange group
Who can run it on a fileThe file's owner or rootRoot to change the owner; the owner can change the group to one of their own groupsThe owner (to a group they are in) or root
Typical syntaxchmod 640 file or chmod g+r filechown user:group filechgrp group file
Recursive flag-R-R-R
Copy from a reference file--reference=FILE--reference=FILE--reference=FILE
Common useMake a script executable, lock down a private keyHand a web root to the service accountGive a team shared access to a project folder

chmod: change what people can do

chmod edits the mode bits. It has two notations, and both are worth knowing.

Octal (numeric) mode

Each digit is the sum of read (4), write (2) and execute (1). The three digits are owner, group and other. An optional leading digit sets the special bits: setuid (4), setgid (2) and sticky (1).

chmod 600 ~/.ssh/id_ed25519      # owner read/write, nobody else
chmod 644 index.html             # owner read/write, everyone read
chmod 750 deploy.sh              # owner all, group read/execute, others none
chmod 2775 /srv/shared           # setgid on a directory plus rwxrwxr-x

Octal mode replaces all the bits at once. That is useful when you know the exact final state, and risky when you only meant to change one bit.

Symbolic mode

Symbolic mode names who (u, g, o, a), an operator (+, -, =) and the permissions (r, w, x, X, s, t).

chmod u+x backup.sh              # add execute for the owner only
chmod g+w,o-rwx project.txt      # group can write, others lose everything
chmod a=r notice.txt             # everyone read, nothing else
chmod -R u=rwX,g=rX,o= /srv/app  # files and dirs, executable bit only where it makes sense

Capital X adds execute only to directories and to files that already have execute set for someone. In a recursive change, that keeps directories enterable without turning every text file into an "executable".

Special bits in brief

  • setuid on an executable makes it run with the file owner's privileges (/usr/bin/passwd is the classic example). Treat any new setuid file as a security event.
  • setgid on a directory makes new files inherit the directory's group. This is the usual way to build a shared team folder.
  • sticky on a directory stops users from deleting files they do not own, which is why /tmp is mode 1777. Our post on sticky bits in Linux file management covers this in detail.

chown: change who owns the file

chown sets the owner, and with a colon it can set the group in the same command.

sudo chown nginx index.html             # owner only
sudo chown nginx:nginx index.html       # owner and group
sudo chown :www-data index.html         # group only (same effect as chgrp)
sudo chown deploy: app.jar              # owner deploy, group = deploy's login group
sudo chown -R appuser:appuser /opt/app  # whole tree
sudo chown --reference=good.conf bad.conf

A few behaviours trip people up:

  • Only root can give files away. Linux restricts changing a file's owner to privileged processes. If any user could hand a file to someone else, they could dodge disk quotas or plant files that appear to belong to another account.
  • The setuid and setgid bits get cleared. According to the Linux chown(2) man page, when the owner or group of an executable file changes, the kernel clears setuid and setgid. If a binary needs them, run chmod again after chown.
  • Symbolic links. By default, GNU chown changes the file a symlink points to. Use -h to change the link itself. During -R, the default is not to follow symlinks that point to directories (-P), which is what you want on shared systems.
  • Numeric IDs work too. chown 1001:1001 file is common inside containers, where the image may not have a matching user name.

chgrp: change only the group

chgrp is the narrow tool. It changes the group and leaves the owner untouched.

chgrp developers design.md          # you own the file and are in developers
sudo chgrp -R qa /srv/test-reports  # whole directory tree
chgrp --reference=template.txt new.txt

The main reason to keep chgrp in your toolkit is permissions: a regular user can run it without sudo, as long as they own the file and belong to the target group. With chown, people tend to reach for sudo out of habit, which hides permission problems instead of fixing them. To learn how groups are created and assigned, read group management in Linux and how it works with permissions.

Which command should you use? Common tasks

TaskCommandWhy this one
Make a script runnablechmod u+x run.shOwnership is fine, only the mode needs to change
SSH refuses your key ("permissions too open")chmod 600 ~/.ssh/id_ed25519OpenSSH rejects private keys readable by others
Web server cannot read files you uploaded as rootsudo chown -R nginx:nginx /var/www/siteWrong owner; fix ownership first, then check modes
Team needs to edit a shared foldersudo chgrp -R devs /srv/proj then sudo chmod -R g+rwX /srv/proj and sudo chmod g+s /srv/projGroup change, group write, and setgid so new files keep the group
Container volume owned by the wrong UIDsudo chown -R 1000:1000 ./dataContainer processes match by numeric ID, not name
Copy one file's settings to anotherchmod --reference=a b and chown --reference=a bAvoids guessing the exact mode or owner

Recursive changes without breaking things

Most damage from these commands comes from -R on the wrong path. Some habits that help:

  1. Look before you change. Run ls -ld path and find path -maxdepth 2 -ls | head first.
  2. Use -c or -v. chmod -c and chown -c print only what actually changed, which makes mistakes obvious.
  3. Separate files and directories when you need different modes.
    find /srv/app -type d -exec chmod 750 {} +
    find /srv/app -type f -exec chmod 640 {} +
  4. Add --preserve-root. GNU chmod, chown and chgrp accept it to refuse a recursive run on /. It is not on by default for these three commands, so some admins add it through a shell alias.
  5. Never "fix" access with chmod -R 777. It gives every account and every compromised process write access. Find out which user the process runs as (ps -o user= -p PID) and grant that user or its group what it needs.

Beyond the three commands: ACLs, SELinux and umask

chmod, chown and chgrp control the classic Unix permission model. Three other layers often explain why access still fails after the modes look right:

  • POSIX ACLs give extra users or groups access without changing the owner or group. Use getfacl and setfacl. A + at the end of the ls -l mode string tells you an ACL exists, and the group bits shown by chmod then act as the ACL mask.
  • SELinux on RHEL, Fedora and related systems can deny access even with mode 777. Check the context with ls -Z. Our SELinux in RHEL 10 guide explains how to read and restore contexts.
  • umask decides the starting mode of new files. A umask of 022 produces 644 files and 755 directories; 027 removes all access for others.

Practising for the RHCSA exam

Ownership and permission tasks appear in Red Hat's RHCSA objectives under managing users, groups and file permissions, including creating collaborative directories with setgid. Practise building a shared directory from scratch: create a group, add users, chgrp the directory, set 2770, and confirm a new file inherits the group. Our RHEL 10 RHCSA exam guide lists the full objectives, and the RHCSA training course (classroom in Kharadi, Pune, or live online) works through these labs on RHEL.

Frequently asked questions

What is the main difference between chmod and chown?

chmod changes permissions (what the owner, group and others can do). chown changes ownership (which user and group the file belongs to). If the right person owns a file but cannot write to it, use chmod. If the wrong person owns it, use chown.

Is chgrp the same as chown :group?

Yes, the result is the same. chown :devs file and chgrp devs file both set the group to devs and leave the owner alone. chgrp is a little clearer to read, and both work for a regular user who owns the file and belongs to the group.

Why do I get "Operation not permitted" with chown?

Changing a file's owner needs root privileges on Linux. A regular user cannot give a file to someone else, even a file they own. Run it with sudo if you are authorised, or use chgrp if you only need to change the group.

What does chmod 755 mean?

The owner gets read, write and execute (7). The group and others get read and execute (5). It is common for directories and for scripts or programs that other users need to run but not edit.

Does chown change file permissions?

It does not change the read, write and execute bits. On Linux it does clear the setuid and setgid bits when the owner or group of an executable changes, so check ls -l afterwards if the file relied on them.

Should I use octal or symbolic mode with chmod?

Use octal when you want to set the exact final permissions, for example 600 on a private key. Use symbolic when you want to change one thing and keep the rest, for example g+w.

How do I change ownership of a directory and everything inside it?

Use sudo chown -R user:group /path. Check the path first, and add -c to print what changed. For permissions on the same tree, chmod -R u=rwX,g=rX,o= /path keeps directories usable without making files executable.

Why can't a service read a file even after chmod 644?

Every parent directory also needs execute (search) permission for that user, and on RHEL-based systems SELinux may block access regardless of mode. Check the parents with namei -l /full/path and the SELinux context with ls -Z.

References

Interested in learning more?Get a callback from our training advisors.

What's Your Reaction?

Like Like 1
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.