chmod +x fixperms
for i in `ls -A /var/cpanel/users` ; do ./fixperms $i ; done
Created
February 1, 2024 17:44
-
-
Save u007/86ea7096df2b5a400ba3839b6ddddbaf to your computer and use it in GitHub Desktop.
fix cpanel permission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# source: https://www.casbay.com/guide/kb/script-to-fix-cpanel-account-permissions-2 | |
if [ "$#" -lt "1" ]; then | |
echo "Must specify at least one user" | |
exit 1 | |
fi | |
for user in "$@" | |
do | |
HOMEDIR=$(getent passwd "$user" | cut -d: -f6) | |
if [ ! -f "/var/cpanel/users/$user" ]; then | |
echo "$user user file missing, likely an invalid user" | |
elif [ -z "$HOMEDIR" ]; then | |
echo "Couldn't determine home directory for $user" | |
else | |
echo "Setting ownership for user $user" | |
chown -R "$user":"$user" "$HOMEDIR" | |
chmod 711 "$HOMEDIR" | |
chown "$user":nobody "$HOMEDIR/public_html" "$HOMEDIR/.htpasswds" | |
chown "$user":mail "$HOMEDIR/etc" "$HOMEDIR/etc/"*/shadow "$HOMEDIR/etc/"*/passwd | |
echo "Setting permissions for files and directories for $user" | |
find "$HOMEDIR" -type f -exec chmod 644 {} \; -print | |
find "$HOMEDIR" -type d -exec chmod 755 {} \; -print | |
find "$HOMEDIR" -type d -name cgi-bin -exec chmod 755 {} \; -print | |
find "$HOMEDIR" -type f \( -name "*.pl" -o -name "*.perl" \) -exec chmod 755 {} \; -print | |
chmod 750 "$HOMEDIR/public_html" | |
if [ -d "$HOMEDIR/.cagefs" ]; then | |
chmod 775 "$HOMEDIR/.cagefs" | |
chmod 700 "$HOMEDIR/.cagefs/tmp" | |
chmod 700 "$HOMEDIR/.cagefs/var" | |
chmod 777 "$HOMEDIR/.cagefs/cache" | |
chmod 777 "$HOMEDIR/.cagefs/run" | |
fi | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment