🐧 How to set permissions on all 755 directories and all 644 files

Safety always comes first.

On Linux / Unix systems, it is first of all recommended to keep your files secure on your systems.

Many newbies set file permissions to 777 on production servers to avoid any kind of permissions issue.

But they make big mistakes when setting write permissions on open servers.

Use the previous guide to find files with 777 privileges on Linux.

🐧 How to find all files with 777 permissions on Linux

It is always recommended to maintain minimum file and directory permissions.

The web application framework might suggest keeping the permissions for all directories at 755 and all files at 644.

Let’s take a look at this with examples.

Recursive change of rights

Change the directory with the cd command to your desired location where you need to assign permissions for all directories to 755 and all files to 644.

cd /home/user/public_html 

Then use the first chmod 755 command for all directories and subdirectories.

The second command will change the permissions for all files to 0644 (chmod 644) in the directory tree.

find . -type d -exec chmod 0755 {} ;
find . -type f -exec chmod 0644 {} ; 

You can also change the resolution using the xargs command to make it faster:

find . -type d -print0 | xargs -0 chmod 755
find . -type f -print0 | xargs -0 chmod 644 

The permissions on directory 0755 are similar to “rwxr-xr-x”, and the permissions on file 644 are “rw-r – r–”.

How to change permissions for specific files

Instead of changing the permissions for all files, you can also target specific files with similar extensions.

For example, you have a PHP application installed on your server.

And you don’t want to let others run php files.

Use the following command to chmod 0640 for all php files:

find . -type f -name "*.php" -exec chmod 0640 {} ; 


In this tutorial, you learned how to change permissions with chmod on files or directories available in a directory tree.