Wednesday, June 1, 2016

How to Fix Permissions on Files and Directories by SSH

Sometimes plugins or other features can mess up the permissions for a file or directory(folder) on your site and make it impossible for you to access something or upload something. The easiest way to fix this is with SSH access. If you do not have SSH access, contact your host and see if they allow it and can enable it for you.

To get SSH access enabled on BlueHost, see: http://helpdesk.bluehost.com/index.php/kb/article/000180

You can use the following two lines to reset your permissions. Note that the default directory permissions are 755 and the default file permissions are 644, so that is what I will show here, however, if your webhost says you need other permissions for something, then you can change the numbers. Beware of 777 permissions though, as they are a security threat! If you are told to use 777, first try it with 755 and 644, if that doesn’t work, then carefully add 777 permissions only where you need it.

Here are the SSH commands to fix your permissions on a mass level:
find ~/public_html -type d -exec chmod 755 {} \;
find ~/public_html -type f -exec chmod 644 {} \;
Basically, the format is to find, or look, in the path of ~(which means home) and then in public_html. (If you want to look in a different directory, you can change this. e.g. ~/public_html/myblog) And then it looks for the document type, be it directory (d) or file (f), and executes the chmod(change mode) command to change the permissions on all results.

Be very careful with these commands!
If you accidentally break something, it can be difficult to fix. For example, if you have cgi or perl files, they will need 755 permissions instead of 644 in order to operate properly. If you have questions in regards to this, you might want to ask first.
Be Sociable, Share!

No comments:

Post a Comment