{"id":9369,"date":"2021-01-07T04:58:46","date_gmt":"2021-01-07T09:58:46","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=9369"},"modified":"2021-12-04T06:31:38","modified_gmt":"2021-12-04T06:31:38","slug":"bulk-set-permissions-directories-755-files-644","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/bulk-set-permissions-directories-755-files-644\/","title":{"rendered":"How to Bulk set Permissions of Directories to 755 and Files to 644"},"content":{"rendered":"\n
This guide will show you how to set permissions of all directories to 755 and all files to 644 in your web application for better security.<\/p>\n\n\n\n
If you are not quite familiar with file or directory permissions then start by reading this article about chmod commands<\/a>. There we explain how to set the required permissions on any Linux<\/a> system. The article also explains what permissions 755 and 644 grant.<\/p>\n\n\n\n It is always advised to keep the file and directory permissions to minimal. As a general practice, many web application frameworks suggest that developers maintain permissions for all directories at 755 and all files at 644.<\/p>\n\n\n\n You may find that your web application has hundreds of files if not thousands and dozens of directories. It would be a nightmare to try and set the permissions of each file and directory individually.<\/p>\n\n\n\n The good news is there is a better way.<\/p>\n\n\n\n Navigate to the directory with the cd<\/strong><\/em> command to get to the desired location under which you need to change the permissions. Such as:<\/p>\n\n\n\n We will then run two commands. The first will find all directories in the path and change their permissions to 755 and the second will find all files and change their permissions to 644.<\/p>\n\n\n\n You can also add the -name directive to change a specific file type. This example shows how to set permissions for only PHP<\/a> files:<\/p>\n\n\n\n With that, you should be more efficient when changing file permissions.<\/p>\n","protected":false},"excerpt":{"rendered":" This guide will show you how to set permissions of all directories to 755 and all files to 644 in your web application for better security. If you are not…<\/p>\n","protected":false},"author":1,"featured_media":9370,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,16],"tags":[121,183,313,354,424,433,526,598,604],"yoast_head":"\nHow to Set Permissions Recursively<\/h2>\n\n\n\n
$ \/var\/www\/html<\/code><\/pre>\n\n\n\n
$ find . -type d -exec chmod 755 {} +\n$ find . -type f -exec chmod 644 {} +<\/code><\/pre>\n\n\n\n
$ find . -type f -name "*.php" -exec chmod 644 {} +<\/code><\/pre>\n\n\n\n