Dev.to Security 🔐 Cybersecurity 👁 0

chmod Explained: Stop Guessing Permissions with 777

Almost everyone has typed chmod 777 to make an error go away. Here is how permissions actually work, so you stop doing it. The three digits Each digit is a sum: read = 4, write = 2, execute = 1. The digits ar

Almost everyone has typed chmod 777 to make an error go away. Here is how permissions actually work, so you stop doing it.

The three digits

Each digit is a sum: read = 4, write = 2, execute = 1. The digits are owner, group, others. So 640 means owner read+write, group read, others nothing.

Common values

  • 644 files: owner writes, everyone reads
  • 755 directories and scripts: owner full, others read+execute
  • 600 private keys (SSH refuses keys that are more open)
  • 700 private directories

Why 777 is a bug, not a fix

It lets any user or compromised process modify the file. The real cause is usually wrong ownership: fix it with chown instead.

Directories need execute

Without x on a directory you cannot enter it or access files inside, even if the files are readable.

Special bits

setuid (4000), setgid (2000) and sticky (1000) change how execution and deletion behave. Use sparingly.

Quick conversion

To convert between rwxr-xr-x and octal I use the free chmod calculator. It runs entirely in your browser.

More free client-side tools: webdevtoolbox.com.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.