Skip to content

Instantly share code, notes, and snippets.

@u007
Created February 1, 2024 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u007/86ea7096df2b5a400ba3839b6ddddbaf to your computer and use it in GitHub Desktop.
Save u007/86ea7096df2b5a400ba3839b6ddddbaf to your computer and use it in GitHub Desktop.
fix cpanel permission

to fix all permissions

chmod +x fixperms
for i in `ls -A /var/cpanel/users` ; do ./fixperms $i ; done
#!/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