Fixing File and Folder Permissions Using SSH

Properly setting file and folder permissions is crucial for ensuring the security and functionality of your website or application hosted on a server. In this step-by-step tutorial, we’ll guide you through the process of fixing file and folder permissions using SSH (Secure Shell) commands. We’ll specifically focus on setting the correct permissions using the “chmod” command.

Step 1: Connect to the Server

Start by establishing an SSH connection to the server where your files and folders are located. Use your preferred SSH client or the terminal on your local machine to connect to the server.

Step 2: Navigate to the Target Directory

Once connected, navigate to the directory containing the files and folders for which you want to fix the permissions. You can use the “cd” command to change directories. For example, if the target directory is “/home/user/public_html”, execute the following command:

cd /home/user/public_html

Step 3: Fix File Permissions

To set the correct permissions for files, use the following command:

find /home/user/public_html -type f -exec chmod 644 {} \;

This command uses the “find” command to locate all files (“-type f”) in the specified directory and its subdirectories. The “-exec” option allows us to execute the “chmod” command for each file found. The “chmod 644” command sets the permissions to read and write for the owner, and read-only for group and others.

Step 4: Fix Folder Permissions

To set the correct permissions for folders (directories), use the following command:

find /home/user/public_html -type d -exec chmod 755 {} \;

Similarly, this command uses the “find” command to locate all directories (“-type d”) in the specified directory and its subdirectories. The “-exec” option allows us to execute the “chmod” command for each directory found. The “chmod 755” command sets the permissions to read, write, and execute for the owner, and read and execute for group and others.

Step 5: Verify Permissions

After executing the commands, it’s essential to verify that the permissions have been set correctly. You can use the “ls -l” command to list the files and folders along with their permissions. For example:

ls -l /home/user/public_html

Check that the file permissions match the intended settings (e.g., 644 for files, 755 for folders).

Conclusion

By following the steps outlined in this tutorial, you can fix file and folder permissions using SSH commands. Using the “find” command in combination with “chmod”, you can ensure that the correct permissions are set to enhance security and functionality. Remember to navigate to the target directory, execute the appropriate command for files and folders, and verify the permissions afterward. With this knowledge, you can confidently manage file and folder permissions through SSH.