User (owner)
Group
Others
Octal644
Symbolicrw-r--r--

chmod 644 <file-or-folder>

Read = 4, write = 2, execute = 1 — add them per group and read the three digits in order (user, group, others). 644 is the standard for files you own, 755 for folders and scripts, 600 for secrets like SSH keys. Avoid 777 on anything reachable from the network, and remember directories also need the execute bit before you can enter them.

How Linux octal permissions are calculated

Linux stores basic permissions as three 3-bit groups: Owner (u), Group (g), and Others (o). Inside each group, Read = 4, Write = 2, and Execute = 1. Adding the enabled bits produces one octal digit between 0 and 7. For example, read + write + execute equals 4 + 2 + 1 = 7, while read-only equals 4 + 0 + 0 = 4.

For everyday homelab files, two modes cover 95% of cases: 755 (rwxr-xr-x) for directories and executable scripts, and 644 (rw-r--r--) for config files and media. Crucially, Linux requires the execute bit (+x) on a directory before a user or Docker container can enter it and read files inside.

Step-by-step example: fixing a Docker backup script and config folder

You created /srv/docker/scripts/backup.sh and a sensitive .env file, and you want root/owner full control without exposing secrets to other local users.

  1. For the directory /srv/docker/scripts: tick Read, Write, Execute for Owner (7), and Read + Execute for Group (5) and Others (5) → 755.
  2. For backup.sh: tick Owner Read/Write/Execute (7) and leave Group/Others blank so only you run it → chmod 700 /srv/docker/scripts/backup.sh.
  3. For .env secrets: tick Owner Read + Write (6) and nothing for Group/Others → chmod 600 /srv/docker/.env.

Result: Cron and your admin user can execute the script cleanly, Docker Compose reads the secrets, and unprivileged system accounts cannot read your database passwords.

Frequently Asked Questions

Why should I never use chmod 777 to fix a broken container?

Mode 777 allows every user and compromised service on the system to read, overwrite, and execute your files. It also silently breaks SSH key authentication and scripts that refuse world-writable files. Fix ownership with chown or use 755/750 instead.

What is the difference between chmod and chown?

chmod changes what permissions the owner, group, and others have (read, write, execute). chown changes who the owner and group actually are. If a container running as PUID 1000 tries to write to a root-owned folder, chown 1000:1000 is usually the clean fix.

Why does my script say Permission denied even with chmod 755?

Check two things: every parent directory in the path needs at least the execute bit for that user, and the filesystem must not be mounted with the noexec flag in /etc/fstab.