Reverse/repair file owner and permissions on CPANEL

The following tutorial is intended for suPHP or FastCGI ONLY
You follow the tutorial on YOUR OWN RISK!

Unfortunately someone (me) has chowned user:user /home -R on a CPanel with Centos 6.7.

  • CENTOS 6.7 x86_64 standard – server
  • WHM 11.50.0 (build 30)

Couple things that might help

 /scripts/upcp --force
 /scripts/mailperms

You can do this running the following commands in shell as root

The real *shit*

CHOWN

for CPAccess in `ls -A /var/cpanel/users`; do chown -R $CPAccess:$CPAccess /home/$CPAccess; done

for CPAccess in `ls -A /var/cpanel/users`; do chown -R $CPAccess:mail /home/$CPAccess/etc /home/$CPAccess/mail; done

for CPAccess in `ls -A /var/cpanel/users`; do chown -R $CPAccess:nobody /home/$CPAccess/public_html; done

CHMOD

For directories
find /home/*/public_html/ -type d -print0 | xargs -0 chmod 0755 # For directories
For files
find /home/*/public_html/ -type f -not -name "*.pl" -not -name "*.cgi" -not -name "*.sh" -print0 | xargs -0 chmod 0644 # For files
For CGI/Scripts
find /home/*/public_html/ -type f -name "*.cgi" -print0 -o -name "*.pl" -print0 -o -name "*.sh" -print0 | xargs -0 chmod 0755 # For CGI/Scripts

 

Resources

https://forums.cpanel.net/threads/the-root-of-all-stupidity.60028/
https://forums.cpanel.net/threads/folder-permission-755-and-file-permission-644-safe.124369/

http://boomshadow.net/tech/fixes/fixperms-script/
https://github.com/PeachFlame/cPanel-fixperms

http://djlab.com/2009/06/cpanel-suphp-chmod-all-files-644-and-all-folders-755/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.