I've got some issues with file permissions which I'm trying to resolve...
I have two sites and they both have the same permissions as far as I can tell but for some reason one site can upload files / read the files in WordPress' media explorer however the other site doesn't.
The server in question is a AlmaLinux server running WHM/cPanel with CloudLinux LVE and LiteSpeed Web Server.
The permissions are as follows:
/home/account/
has account:account
and 711
/home/account/public_html/
has account:account
and 755
/home/account/public_html/.htaccess
has account:account
and 644
/home/account/public_html/website
has account:account
and 755
/home/account/public_html/website/.htaccess
has account:account
and 644
/home/account/public_html/website/wp-config.php
has account:account
and 600
because the file needs to be able to be edited via FTP with the cPanel account login.
/home/account/public_html/website/*.php
have account:account
and 644
After this all other files/folders are:
/home/account/public_html/website/[ALL DIRECTORIES]
have account:account
and 755
/home/account/public_html/website/[ALL FILES]
has account:account
and 644
The following files have all been setup by WordFence Security automatically:
/home/account/public_html/website/wp-content/wflogs/has
account:accountand
755 /home/account/public_html/website/wp-content/wflogs/*.php
have account:account
and 600
By that logic, should Sucuri Security also have the same 600 permissions for their files?/home/account/public_html/website/wp-content/uploads/sucuri/*.php
I created the following script to double check the permissions/ownership and both sites return no issues...
#!/bin/bash
# Define constants
ACCOUNT=account
WORDPRESS=website
ACCOUNT_PATH="/home/${ACCOUNT}"
WORDPRESS_PATH="${ACCOUNT_PATH}/public_html/${WORDPRESS}"
WORDFENCE_LOGS_PATH="${WORDPRESS_PATH}/wp-content/wflogs"
# Function to check file permissions
check_perms() {
local path="$1"
local type="$2" # "file" or "dir"
local perms="$3"
local owner="$4"
local group="$5"
local current_perms=$(stat -c "%a" "$path")
local current_owner=$(stat -c "%U" "$path")
local current_group=$(stat -c "%G" "$path")
if [ "$type" == "file" ] && [ "$current_perms" != "$perms" ]; then
echo "$path - File permissions should be $perms but are $current_perms."
elif [ "$type" == "dir" ] && [ "$current_perms" != "$perms" ]; then
echo "$path - Directory permissions should be $perms but are $current_perms."
fi
if [ "$current_owner" != "$owner" ]; then
echo "$path - Owner should be $owner but is $current_owner."
fi
if [ "$current_group" != "$group" ]; then
echo "$path - Group should be $group but is $current_group."
fi
}
export -f check_perms
export ACCOUNT ACCOUNT_PATH WORDPRESS WORDPRESS_PATH WORDFENCE_LOGS_PATH
# Check specific directories and files
check_perms "${ACCOUNT_PATH}/" "dir" "711" "$ACCOUNT" "$ACCOUNT"
check_perms "${ACCOUNT_PATH}/public_html/" "dir" "755" "$ACCOUNT" "$ACCOUNT"
check_perms "${ACCOUNT_PATH}/public_html/.htaccess" "file" "644" "$ACCOUNT" "$ACCOUNT"
check_perms "$WORDPRESS_PATH" "dir" "755" "$ACCOUNT" "$ACCOUNT"
check_perms "$WORDPRESS_PATH/.htaccess" "file" "644" "$ACCOUNT" "$ACCOUNT"
check_perms "$WORDPRESS_PATH/wp-config.php" "file" "600" "$ACCOUNT" "$ACCOUNT"
# Correctly check all PHP files in the WordPress root directory
find "$WORDPRESS_PATH" -maxdepth 1 -type f -name "*.php" ! -name "wp-config.php" -exec bash -c 'check_perms "$0" "file" "644" "$ACCOUNT" "$ACCOUNT"' {} \;
# Check all directories and files under the WordPress installation
find "$WORDPRESS_PATH" -type d ! -path "$WORDFENCE_LOGS_PATH" -exec bash -c 'check_perms "$0" "dir" "755" "$ACCOUNT" "$ACCOUNT"' {} \;
find "$WORDPRESS_PATH" -type f ! -path "$WORDFENCE_LOGS_PATH/*" ! -name "*.php" -exec bash -c 'check_perms "$0" "file" "644" "$ACCOUNT" "$ACCOUNT"' {} \;
# Special handling for WordFence Security's wflogs directory and files
check_perms "$WORDFENCE_LOGS_PATH" "dir" "755" "$ACCOUNT" "$ACCOUNT"
find "$WORDFENCE_LOGS_PATH" -type f -name "*.php" -exec bash -c 'check_perms "$0" "file" "600" "$ACCOUNT" "$ACCOUNT"' {} \;
attachment
that represent the files (on many sites the files aren't on the server at all but on a 3rd party). Also the correct ownership and permissions for you are unique and super specific to you, you need to phrase your question in a way that it works for all people with that question, not just you