cPanel - Script to fix permissions/ownership under a reseller


Fix permissions/ownership under a reseller


                             I recently had an issue with incorrect ownership and permissions  of all files under a reseller in cpanel after the manual migration from a Kloxo and plesk server.
I created the following script to fix permissions under a reseller.

You just copy the following script in a file fixperm.sh, then

# chmod +x fixperm.sh

Give the reseller user name in the <reseller> field when running the fixperm.sh. If no parameter is given, it will fix permissions/ownership of all accounts in the server.

# sh fixperm.sh <reseller>


#====================================================================


reseller=$1
echo -e "Fixing Permissions of account under $reseller \n"
for i in `grep -rl "OWNER=$reseller" /var/cpanel/users | cut -d/ -f5`
do
if [ "$i" != "root" ]; then
chown -R $i:$i /home/$i
chown $i:nobody /home/$i/public_html
chown $i:mail /home/$i/etc 
find /home/$i/public_html/ -type d -exec chmod 755 "{}" \;
find /home/$i/public_html/ -type f -exec chmod 644 "{}" \;
chmod 750 /home/$i/etc /home/$i/public_html
echo $i
fi
done


#====================================================================


That's it...

Leave a Reply