Interview Prep/Linux/Users, groups and access control

A developer accidentally ran `chmod -R 777 /var/www`. How do you restore sane permissions?

BeginnerScenarioUsers, groups and access control
Answer

Situation read → Reset directories and files separately.

What I'd do →

sudo chown -R www-data:www-data /var/www
sudo find /var/www -type d -exec chmod 755 {} +
sudo find /var/www -type f -exec chmod 644 {} +

Then re-apply exceptions such as writable upload dirs (775) or executable scripts, and check config files holding secrets (640).

Why → Directories need x to be entered; files usually should not be executable.

Interview tip → If the files came from a package, rpm --setperms pkg or reinstalling restores the original modes.

All Linux questions Roadmap: Linux

More on Users, groups and access control