# Linux permissions: chmod and chown

> chmod sets mode bits (who can read, write, execute); chown changes owner and group under privilege rules.

Source: https://fullbytedeveloper.com/blog/linux-permissions-chmod-chown
Published here: 2026-12-03, updated 2026-12-03

File mode bits say who may read, write, or execute; ownership says which user and group those "owner" bits apply to [1][2]. The kernel checks both when a process opens a path. Learn the nine bits and the privilege rules for `chown` before you reach for `chmod 777` on a deploy box.

## One minute: set two modes you will reuse

```bash
mkdir -p /tmp/perm_lab && touch /tmp/perm_lab/notes.txt /tmp/perm_lab/run.sh /tmp/perm_lab/secret
chmod 644 /tmp/perm_lab/notes.txt
chmod 755 /tmp/perm_lab/run.sh
chmod 600 /tmp/perm_lab/secret
ls -l /tmp/perm_lab
stat -c '%a %n' /tmp/perm_lab/*
```

Captured output on this host (coreutils, 2026-12-03):

```text
-rw-r--r-- 1 ubuntu ubuntu 0 Dec  3 12:13 notes.txt
-rwxr-xr-x 1 ubuntu ubuntu 0 Dec  3 12:13 run.sh
-rw------- 1 ubuntu ubuntu 0 Dec  3 12:13 secret
644 /tmp/perm_lab/notes.txt
755 /tmp/perm_lab/run.sh
600 /tmp/perm_lab/secret
```

`644` is a normal shared text file. `755` is a script or directory others may traverse. `600` is private (keys, env files) [1].

## Match octal to the nine bits

GNU `chmod` accepts symbolic modes (`u+x`, `go-w`) or octal modes [1]. Octal digits add 4 (read), 2 (write), 1 (execute) for owner, group, and others in order [1].

```text
         owner        group       others
         r w x        r w x       r w x
octal    4 2 1        4 2 1       4 2 1

644  =  rw- r-- r--
755  =  rwx r-x r-x
600  =  rw- --- ---
```

Letters `ugoa` select whose bits change; operators `+`, `-`, and `=` add, remove, or set bits [1]. Symbolic form is easier when you only add execute for the owner: `chmod u+x deploy.sh`.

<figure>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 260" role="img" aria-label="Owner group others bits map to chmod octal digits">
  <defs>
    <marker id="permArrow" markerWidth="10" markerHeight="10" refX="8" refY="3" orient="auto">
      <path d="M0,0 L8,3 L0,6 Z" fill="#14b8a6"/>
    </marker>
  </defs>
  <rect x="0" y="0" width="720" height="260" rx="12" fill="#0b1f3a"/>
  <text x="24" y="36" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="16" font-weight="700">chmod 755</text>
  <rect x="24" y="56" width="180" height="80" rx="8" fill="#123052" stroke="#14b8a6" stroke-width="2"/>
  <text x="36" y="88" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">owner 7 = rwx</text>
  <text x="36" y="114" fill="#cbd5e1" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">4+2+1</text>
  <path d="M204 96 H248" stroke="#14b8a6" stroke-width="3" fill="none" marker-end="url(#permArrow)"/>
  <rect x="256" y="56" width="180" height="80" rx="8" fill="#123052" stroke="#f59e0b" stroke-width="2"/>
  <text x="268" y="88" fill="#f59e0b" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">group 5 = r-x</text>
  <text x="268" y="114" fill="#cbd5e1" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">4+0+1</text>
  <path d="M436 96 H480" stroke="#14b8a6" stroke-width="3" fill="none" marker-end="url(#permArrow)"/>
  <rect x="488" y="56" width="200" height="80" rx="8" fill="#123052" stroke="#64748b" stroke-width="2"/>
  <text x="500" y="88" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">others 5 = r-x</text>
  <text x="500" y="114" fill="#cbd5e1" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">4+0+1</text>
  <text x="24" y="180" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">chown alice:devs file</text>
  <path d="M200 174 H248" stroke="#14b8a6" stroke-width="3" fill="none" marker-end="url(#permArrow)"/>
  <text x="260" y="180" fill="#cbd5e1" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">changes who the owner/group bits apply to (privilege rules)</text>
  <text x="24" y="230" fill="#cbd5e1" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">Directory execute means traverse; file execute means run.</text>
</svg>
</figure>

*Three octal digits encode owner, group, and others; chown picks which identities those digits refer to.*

## Change ownership with chown

```bash
chown alice:devs deploy.sh
```

GNU `chown` sets owner and optional group (`OWNER:GROUP`) [2]. Only a privileged process may change the owner; an ordinary owner may move the group to a group they belong to [3]. `sudo chown` is the usual path when a deploy user must own files created as root.

A service running as `www-data` needs read on files your login user created only if ownership or group membership aligns. `chmod` cannot fix a group membership problem you created with `usermod`.

## Directories are special

Execute on a directory means permission to search the directory (lookup names). Read means list names with `ls`. Write means create or delete entries in that directory (subject to sticky-bit rules on shared dirs) [1].

A common deploy trap: script is `755` but it lives in a directory with `700` owned by someone else. Others cannot traverse to reach the script no matter what the file bits say.

## Symlinks and chmod

GNU chmod does not change symlink mode bits themselves; for links listed on the command line it changes the target file instead [1]. GNU chown also follows symlinks by default and changes the referent; pass -h/--no-dereference when you mean the link node [2]. Verify with ls -l and readlink.

## umask and defaults

New files get a default mode minus umask. `umask 022` yields world-readable new files (`644` for files with typical defaults). `umask 077` keeps new files private. Check `umask` in shells that spawn daemons; a loose umask leaks logs and uploads.

```bash
umask
touch /tmp/umask_demo && ls -l /tmp/umask_demo
```

Captured on this host:

```text
0022
-rw-r--r-- 1 ubuntu ubuntu 0 Dec  3 12:13 /tmp/umask_demo
```

With umask `0022`, the kernel subtracts group and other write bits from the default `666` file creation mode, leaving `644` [1].

## Sticky bit and setuid (names only)

Setuid on an executable lets a program run with the owner's effective UID. Sticky on a world-writable directory (for example `/tmp`) restricts deletes to the file owner. This page does not teach setuid scripting; know the letters exist when `ls -l` shows `s` or `t` instead of a plain `x`.

## chgrp without chown

An owner may `chgrp` to a group they belong to without root [3]. Useful when a deploy user and `www-data` share a group for read-only config. Changing owner still needs privilege [3].

## Keep deploy scripts boring

Prefer the least mode that still works: private keys `600`, shared config often `644`, directories that must be entered need execute/search bits [1]. Fix ownership when a service user must read files your login user created [2][3]. Audit `chmod -R` before you run it on a tree you care about.

SSH requires tight `~/.ssh` modes ([ssh keys for developers](/blog/ssh-keys-for-developers)). Everyday navigation commands live in [essential Linux commands part 1](/blog/essential-linux-commands-developers-part-1). Who the kernel checks against is a [process](/blog/what-is-a-process).

## macOS versus Linux quirks

macOS ships BSD `chmod` plus ACL flags on some volumes. Linux GNU chmod differs slightly on symlinks and recursion defaults [1][2]. Scripts that must run on both should document which chmod variant you used. Docker bind mounts inherit host permissions; fixing modes inside the container does not help if the mounted file stays `600` on the host.

## Audit with find when trees drift

```bash
find /tmp/perm_lab -type f -perm 600 -ls
```

Use `find` on a teaching directory you control. System trees need sudo and care. Searching for unexpected `777` directories after a bad deploy script is the same idea with a mode you do not want.

## ACLs and beyond this page

This page stays with classic owner/group/others bits [1][2]. POSIX ACLs (`setfacl`) extend who can access a file without changing primary owner. Capabilities and SELinux add labels this article does not cover. Reach for ACLs when one shared directory needs many users with different rights.

## Common mistakes

`chmod 777` to silence `Permission denied`. You mask the real owner or service user mismatch.

Forgetting execute on directories in the path to a script. The script bits do not matter if traversal fails.

Chowning everything to yourself on a shared server without coordinating groups. Services break when they no longer match unit file `User=`.

Running `chmod -R 777` on vendor or `node_modules` trees. Huge, unnecessary, and hides mistaken uploads.

Treating group read as enough to run scripts. Execute is a separate bit; `646` does not run.

Using `chown` without privilege to take files from root. Only privileged processes change owner [3].

Treating `chmod` on a symlink path as chmod on the link when you meant the target. Verify with `ls -l`.

## Read the error the kernel actually sent

`Permission denied` on `./deploy.sh` can mean the file lacks execute, a directory in the path lacks execute/search, or the interpreter in the shebang is not executable for you. `ls -l` on the file alone is not enough; walk each path component with `namei -l /full/path/to/deploy.sh` when you have it, or manually `ls -ld` each directory. Mode `644` on a script looks readable and still will not run without the execute bit [1].

`Operation not permitted` on `chown` is the privilege rule talking [3]. Switching to `chmod 777` does not grant ownership. Fix the user the service unit runs as, or use `sudo` with intent when a root-owned tree must move to a deploy user.

## Recipes that stay boring on purpose

Private SSH key material: directory `700`, key file `600`, public key often `644` ([ssh keys for developers](/blog/ssh-keys-for-developers)).

Web content readable by the server user: files `644`, directories `755`, ownership either the deploy user with group read for the server group, or the server user with careful write isolation on upload directories only [1][2].

Shared drop directory: sticky bit on the directory so people cannot delete each other's files, plus group write if that is the collaboration model. Do not confuse sticky with setuid.

## Containers and bind mounts

A file mode is a property of the inode on the filesystem that holds it. Bind-mounting a host file into a container preserves those bits. Changing modes inside the container namespace on a bind mount changes the host file. Changing ownership may require privileges that the container user does not have. Image `USER` directives do not rewrite modes on volumes you mount at runtime. Debug with `ls -l` from both sides of the mount before you rewrite Dockerfiles in a panic.

## Numeric modes in Ansible and Docker

Playbooks and `RUN chmod` lines love octal because it is compact and reviewable in a diff [1]. Prefer explicit modes over relying on umask inside a build layer you do not control. When a Dockerfile copies a secret for a build step, delete it in a later layer and still assume older layers may exist in a cache until you use a proper secret mount mechanism. Mode `600` in a layer that remains in the image is still readable by anyone who pulls the image.

## Teaching lab you can repeat

```bash
rm -rf /tmp/perm_lab && mkdir -p /tmp/perm_lab/bin
printf '#!/bin/sh\necho ok\n' > /tmp/perm_lab/bin/hello.sh
chmod 644 /tmp/perm_lab/bin/hello.sh
/tmp/perm_lab/bin/hello.sh || true
chmod 755 /tmp/perm_lab/bin/hello.sh
/tmp/perm_lab/bin/hello.sh
```

The first run should fail without execute. The second should print `ok`. That single contrast is the whole execute-bit lesson for files. Repeat it for directories by removing execute from `/tmp/perm_lab/bin` and trying to run the script through that path [1].

Browse the [Dev tools topic](https://fullbytedeveloper.com/blog/topic/dev-tools).

Send this to the friend who chmods everything to 777 to make the error go away.

Image: Dark reflective floor with faint schematic lines. Left: a translucent teal glass cube ringed by three segmented horizontal bands (teal, gold, teal). Right: a solid teal disc, a thick gold 3D arrow, and a glowing gold disc showing a mode or ownership change.
https://fullbytedeveloper.com/media/linux-permissions-chmod-chown/linux-permissions-chmod-chown-venice.webp
The cube is the file; the rings are who may touch it. The teal-to-gold arrow is chmod or chown changing that state on purpose.

## Sources

1. [Linux man-pages: chmod(1), accessed 2026-12-03](https://man7.org/linux/man-pages/man1/chmod.1.html)
2. [Linux man-pages: chown(1), accessed 2026-12-03](https://man7.org/linux/man-pages/man1/chown.1.html)
3. [Linux man-pages: chown(2), accessed 2026-12-03](https://man7.org/linux/man-pages/man2/chown.2.html)
