TOP

Fix User Permissions for cPanel

One thing that annoys me is when cPanel users (or cPanel) chmods themselves out of ownership or rights, so for WHM admins here is a nifty script that is an improvement of sorts over Quick and easy CHMOD fixes

#!/bin/bash
#permfix by solutionsfox
echo "Type the user you want to fix followed by [ENTER]:"
read user
 
#check the user
echo "Checking for valid user..."
grep -q "^$user:" /etc/passwd > /dev/null
if [ $? -eq 1 ]; then
	echo "$user is an invalid user"
	exit 1
else
echo "Running perm fix for $user..."
	if [ -d "/home/$user/public_html" ]; then
		cd /home/$user/public_html
		find /home/$user/public_html -type d -exec chmod 755 {} \;
		find /home/$user/public_html -type f -exec chmod 644 {} \;
		find /home/$user/public_html -type f -name "configuration.php" -exec chmod 444 {} \; #for joomla
		echo "Do you need to repair ownership? y/n"
		read response
		if [ "$response" == "y" ]; then
			echo "Repairing ownership..."
			cd /home/$user
			chown -R $user.$user /home/$user/*
			echo "Finished."
		exit 0
	elif [ "$response" == "n" ]; then
		echo "Finished."
	exit 0
		else echo "ERROR: Check last input."
	exit 1
		fi
		else echo "ERROR: Check home directory manually."
	exit 1
	fi
fi

So, grab the script, put it on your server, make it executable and from then on sh /whereyouputit/fixperms.sh and you’ll be prompted and what-not to fix a user account. Enjoy.

Related Posts:
Read More
TOP

Quick and easy CHMOD fixes

From time to time I have to fix the permissions of entire web directories for one reason or another due to many reasons, user error, script malfunction, system errors or whatever.
(more…)

Related Posts:
Read More

Switch to our mobile site