>_ IzzyLab

Hands-on task

This task is step 15 of the course “Linux: everyday tasks”

Fix up the site's permissions

medium~7 min

After a botched deploy in /srv/site, files and directories have inconsistent permissions. nginx already serves this site — open the Site tab above the terminal: instead of the page there's a 403 Forbidden. Bring the permissions back to normal recursively: directories — 755, files — 644. Then refresh the Site tab — the page should open together with its styles.

What you'll practise:
  • chmod
  • find
  • permissions
  • recursive traversal
  • -exec

Topic breakdown

In Unix, directory and file permissions mean different things: on a directory the x bit is the right to "enter" and access its contents, not "execute". That's why a single recursive chmod -R with one numeric mode always breaks one of the categories: it either makes files executable or strips the ability to enter directories. The correct line of thinking is to handle object types separately: a tool like find can filter the tree by type (-type d / -type f) and apply its own mode to each group via -exec. To verify the result, the -perm predicate with negation helps — it shows objects whose permissions didn't match the target.

What's checked

  1. all directories have permissions 755
  2. all files have permissions 644
  3. the site opens: the page and styles are served with code 200

What it looks like