Fix CPanel account permission and ownership

Fix CPanel account permission and ownership issue with below script, save below code as fixperms.sh and run it as mentioned below. You can run the script from any location of the server (Like /root /home /usr/local/src), it will only fix the CPanel account permission issues.

for i in `ls -A /var/cpanel/users` ; do ./fixperms.sh $i ; done

./fixperms.sh username

=======================================

#!/bin/bash
# Script to fix permissions of accounts
# Written by: Vanessa Vasile 5/13/10
# http://thecpaneladmin.com

if [ “$#” -lt “1” ];then
echo “Must specify user”
exit;
fi

USER=$@

for user in $USER
do

HOMEDIR=$(egrep “^${user}:” /etc/passwd | cut -d: -f6)

if [ ! -f /var/cpanel/users/$user ]; then
echo “$user user file missing, likely an invalid user”

elif [ “$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 user $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

==========================================

Thanks for the wonderful script

Credits: Vanessa Vasile

Source: http://thecpaneladmin.com/fix-account-permissions/

 

Disclaimer: This script is not owned or created by me and it’s shared for knowledge purpose. The credits goes to actual creator and thecpaneladmin.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s