DEV Community

Shubham Chaudhary
Shubham Chaudhary

Posted on

Linux chown Cheat Sheet: Fix Permission Denied Without Breaking Servers

 Your container starts, but the app can't write to the mounted volume. The log says permission denied, and a forum answer says to run a recursive chown as root.

Before you paste it, here is what to know.

The commands you'll use most

chown user file.txt          # change owner
chown user:group file.txt    # change owner and group
chown :group file.txt        # change group only
chown -R user:group folder/  # recursive change
ls -ln file.txt              # verify numeric UID/GID
Enter fullscreen mode Exit fullscreen mode

Why containers make this tricky

A user name on your host may map to a different number inside a container or on a restored backup. When volumes misbehave, check the numeric IDs with ls -ln and use chown 1000:1000 file.txt when the numbers matter more than the names.

Where it goes wrong

  • chown -R with sudo on the wrong path can break SSH logins, cron jobs, and services.
  • chown user: file.txt does not keep the existing group. It switches to that user's login group.
  • Owning an entire web app tree with the web server user lets a compromise rewrite the app's own code.

A safer habit: preview with find, change narrowly, use -c or -v for a record, and verify afterward.

The security angle

Ownership is an access control. Files that root runs or trusts shouldn't belong to low-privileged accounts, and Linux auditd can log ownership changes so a SOC team can review them.

The full guide covers 40+ examples, find-based bulk changes, symlink pitfalls, and auditd rules:

https://www.xpert4cyber.com/2026/09/linux-chown-command-cheat-sheet.html

What is the trickiest permissions bug you have debugged? Share it below.

Top comments (0)