Understand Unix file permissions and fix "permission denied" without opening everything to the world.

What rwx means

  • r (4): read
  • w (2): write
  • x (1): execute (for files) / enter directory (for dirs)

Three triplets: owner, group, others. Example 755 = rwxr-xr-x.

chmod numeric

chmod 644 file.txt    # rw-r--r--
chmod 755 script.sh   # rwxr-xr-x
chmod 600 key.pem     # rw------- (private key pattern)
chmod -R 755 ~/project/public

chmod symbolic

chmod u+x script.sh
chmod go-w sensitive.txt
chmod a+r readme.md

chown & chgrp

sudo chown user:group file
sudo chown -R www-data:www-data /var/www/html

umask

umask        # shows current mask (e.g. 022)
umask 077    # stricter defaults for new files

Safety tips

  • Never chmod 777 on production without a strong reason.
  • For secrets, prefer 600 and correct ownership.
  • Use ls -la to verify before and after.