Chmod Calculator

Chmod Calculator

Calculate Unix/Linux file permissions. Convert between symbolic (rwx) and numeric (755, 644) notation. Free chmod permission calculator online

chmod 755 vs 644 is muscle memory for anyone who has deployed a shell script. The interesting cases are: when do you need 750? What does the sticky bit on /tmp actually do? Why does chmod +x not always make a file executable? This calculator converts between symbolic (u+rwx,g-w,o=r) and numeric (755) notation, shows the bitmask, and explains what special bits (setuid, setgid, sticky) actually achieve in modern Linux.

How permission bits work

Every file has three permission classes: owner (u), group (g), and other (o). Each class has three primary bits: read (r=4), write (w=2), execute (x=1). The numeric mode is the sum: 7 = rwx, 6 = rw-, 5 = r-x, 4 = r--. Three classes × one octal digit each = three-digit chmod. With special bits (setuid=4, setgid=2, sticky=1) you get a fourth leading digit: 4755, 2755, 1777.

Directories use the same bits but they mean different things: r on a directory means "list contents", w means "create, rename, delete files inside", x means "enter the directory / resolve names through it". x without r is "you can cd in and access named files, but cannot ls". This is the basis of "secret directories" — set 0711 on a dir to allow lookup without listing.

Working example: a deploy script and its config

Input

A deploy.sh script that reads /etc/deploy.conf containing API tokens

Output

deploy.sh:           chmod 750 (rwxr-x---)
  Owner can read, write, execute. Group can read and execute (run it).
  Others cannot even see it exists if the parent dir restricts.

/etc/deploy.conf:    chmod 640 (rw-r-----)
  Owner can edit. Group can read. Others get nothing — important, this contains tokens.
  640 is the standard "config file with secrets but readable by service account" mode.

/var/log/deploy.log: chmod 664 (rw-rw-r--)
  Owner and group can append. Others can read for debugging.

750/640 is the "secure but operable" baseline for services with secrets. 755/644 (the chmod defaults) make the config world-readable, which leaks tokens to any local user.

The special bits that matter

  • Setuid (4xxx) — on an executable, runs as the file owner regardless of who invokes it. /usr/bin/passwd uses this so non-root users can update /etc/shadow. Almost never the right answer outside system utilities.
  • Setgid (2xxx) — on an executable, runs as the file group. On a directory, files created inside inherit the directory's group. Useful for shared project directories.
  • Sticky bit (1xxx) — on a directory, files inside can only be deleted by their owner or root. This is why /tmp (mode 1777) lets every user write but stops them deleting each other's files.
  • Capabilities — modern Linux replaces most setuid uses with file capabilities (setcap cap_net_bind_service+ep on a binary lets it bind low ports without full root). Check with getcap; capabilities are not visible in chmod output.

umask: why your new files are 644 by default

umask is the inverse mask applied when a process creates files. Default umask 022 means files are created with mode (0666 & ~022) = 0644, directories with (0777 & ~022) = 0755. For systems where files should never be world-readable, set umask 027 — files become 640, dirs 750. Set it in /etc/profile or the user's shell rc for persistence.

When to reach for this tool

  • You read a tutorial that says chmod 0755 and want to verify what those permissions actually grant before applying to production files.
  • You inherited a Dockerfile or Ansible playbook with mode: "0644" sprinkled everywhere and need to audit which are too permissive.
  • You are setting up a shared SFTP chroot and need to figure out the directory permissions that let multiple users upload to the same dir but not delete each other's files (answer: 1770 with shared group).
  • You are debugging a "permission denied" error and need to translate the ls -l output back to a numeric mode for a chmod fix.

What this tool will not do

  • It will not handle ACLs (getfacl/setfacl). POSIX ACLs add per-user or per-group entries beyond the standard owner/group/other split. ls -l shows a "+" suffix when a file has ACLs; chmod alone cannot see or modify them.
  • It will not handle SELinux or AppArmor contexts. On systems with mandatory access control, even chmod 777 will not bypass policy. Use chcon, audit2allow, or aa-status.
  • It will not check the parent directory permissions. A file at 644 inside a directory at 700 is unreadable by anyone except the directory owner. The effective access depends on every directory in the path.

Frequently asked questions

Why does chmod +x make a file executable but the script still does not run?

Three usual reasons: (1) wrong shebang or missing one — kernel needs #!/bin/sh or similar on line 1 to know how to interpret; (2) Windows-style CRLF line endings — kernel reads #!/bin/bash\r and fails to find /bin/bash\r; (3) noexec mount option on the filesystem (common on /tmp on hardened systems).

What is the difference between 644 and 664?

644 (rw-r--r--) gives only the owner write access. 664 (rw-rw-r--) gives the group write access too. Use 664 for files in a shared project directory where multiple developers need to edit; use 644 for service config that only the owner should modify.

Is chmod 777 ever the right answer?

In production, almost never. Common bad fixes that use 777: "uploads dir is not writable" (the web user needs write, not the world — use 755 with correct ownership), "the cron is not running" (executable on the file, not world-write).

How do I see the numeric mode of an existing file?

stat -c "%a" filename gives the numeric mode (e.g. 644). stat -c "%A" gives the symbolic form (-rw-r--r--). On macOS, stat -f "%Lp" filename.

Why does chmod -R 755 on a directory tree break things?

It applies 755 to files too, making everything executable. Use find . -type d -exec chmod 755 {} \; for directories and find . -type f -exec chmod 644 {} \; for regular files. Or chmod -R u=rwX,go=rX (capital X = "execute if directory, or already executable").

What does the leading "0" mean in chmod 0755?

It is an explicit octal indicator and a placeholder for special bits. 0755 == 755 (no special bits). 4755 has setuid. 2755 has setgid. 1755 has sticky. Some scripts write 0755 to be explicit; chmod treats both as identical numeric input.

Related tools

Last updated · E-Utils editorial team