M. Niyazi Alpay
M. Niyazi Alpay
M. Niyazi Alpay

I've been interested in computer systems since a very young age, and I've been programming since 2005. I have knowledge in PHP, MySQL, Python, MongoDB, and Linux.

 

about.me/Cryptograph

  • admin@niyazi.org

Batch Configuration of Directory and File Permissions for Web Sites on Linux Server

Batch Configuration of Directory and File Permissions for Web Sites on Linux Server

Setting file and directory permissions for websites on a Linux server can sometimes be time-consuming. For example, when using FileZilla with the option to apply to subdirectories selected, or when applying only to folders, the operation can take a long time depending on the number of files on the FTP. When using only the chmod command via SSH, either permissions are applied to everything including all subfolders, or only to those within a single directory. You can adjust the write permissions of files and directories in the current directory and its subdirectories using the following command:

chmod 755 $(find /path/to/file-or-directory -type d)
chmod 644 $(find /path/to/file-or-directory -type f)

-type d (directory) specifies only directories, while -type f (file) specifies only files. Directories should have permissions of 755, and files should have permissions of 644. Instead of typing the file or directory path each time for different sites on the server, saving the following commands with a .sh extension and running them under the directory of the site will be faster:

#!/bin/bash
directory=`pwd`
chmod 755 $(find $directory -type d)
chmod 644 $(find $directory -type f)

It's important to note that this .sh file should only be executed in the directory where the website is located. Running it in a different location could potentially harm the server.

You may also want to read these

There are none comment

Leave a comment

Your email address will not be published. Required fields are marked *