Changing File Permissions for a cPanel User

As I am getting my feet wet with more and more sysadmin stuff, which is pretty fun for me, I’m gonna take a second and record the tricks that I know are going to be useful long term, like the “Auto fix for file permissions and ownership” script. Tim pointed out that often the errors you get after moving over someone’s files are related to ownership and permissions on that specific user’s account. He showed me a quick way to automatically re-write the permissions for all files to be 644 and folders 755 (the standard, as I have come to learn) for just that account.

Through terminal, you wget the script from Github:

wget https://raw.githubusercontent.com/PeachFlame/cPanel-fixperms/master/fixperms.sh

Then run the following command where USER-NAME is the username for the account you are changing file permissions for.

sh ./fixperms.sh -a USER-NAME

It worked a charm, and now I have blogged it here and tagged it sysadmin, which will be where I start to store some of these tricks until they become more familiar.

This entry was posted in sysadmin and tagged . Bookmark the permalink.

7 Responses to Changing File Permissions for a cPanel User

  1. Look at you going all sysadmin! There are -p flags you can use in unix commands (cp for copy, tar for compressing) that are supposed to preserve file permissions.

    Perms are always a beast to battle….

  2. Tim Owens says:

    I’m so glad to have found that script awhile back. This happens more often than people realize. Their FTP client might not be uploading things with proper permissions or somewhere along the way they got changed. Apache helpfully can refuse to load insecure files like PHP files with world-writeable permissions, but then you get nasty errors in the browser with little idea how to fix them. I use this script every time I migrate some from a previous host just for good measure to make sure they’re starting off on the right foot.

  3. I can totally see this being essential. And you see diff environments where owners are owners vs owners are Apache…

    • Tim Owens says:

      That’s a good point, this script also sets all files to be owned by that particular cPanel user since we use suPHP to run Apache as the user rather than “nobody”. Different PHP handlers will require different sets of permissions (although usually 644 for files and 755 for folders is a pretty safe bet).

Leave a Reply

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