DEV Community

Madalin Ignisca
Madalin Ignisca

Posted on • Originally published at madalin.me on

How to reset correct directories and files permissions recursive in linux

Here is what you need to do to reset the right way all files and directories in Linux. Works also on Macos and FreeBSD.

Sad eggs

Open the terminal. Change directory to the directory containing all you want to fix permissions.

We will fix also the owner, optionally.

I am setting OTHERS to 0, but if some services need read access to your directories or files, use 755, respectively 644. I am just a bit more restrictive and set correct the groups depending on how they will be used.

Fix directories:

find . -type d -exec chmod 750 {} \;

Fix the files:find . -type f -exec chmod 640 {} \;

Fix owner:

chmod -R [replace with user]:[replace with group] .

If this are my local files, usually I replace user and group with my username.

If this are in a web project, on a web server, I set user for the user running the application and group for a group the web server belongs to. I normally ensure both belong to that group. Make note you must set your application platform to do an umask of 027. PHP it is in the ini settings ;-)

Retry later

Top comments (0)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay