File Ownership and Permissions
File ownerships and permissions
When working with files and directories on a Linux machine, we often see strings of numbers and letters next to each item. 777, 644, rwxrwxrwx, rwx------, and other combinations will show up when checking files in terminal or the cPanel
read - this permission allows a user to view the contents of a file or directory
write - this permission allows a user to modify the contents of a file or directory
execute - this permission allows a user to execute the file or access contents of a directory
These file permissions are assigned to three groups of users - the owner of the file, the group of the file, and other users, which are explained here:
This command changes the owner and the group, represented by the user:group portion of the command, to be the cptest user. After running that, we'll see this is now assigned to that cptest user when we check the file again: Since that file has 644 permissions already, and is now owned by the cptest user, they can visit that PHP page in a browser to start the installation. Although we didn't need to change permissions in this example, here is the command we would have needed to change the permissions to 644, the standard permissions for a PHP file, just so you have it for reference:
Example 2 - A command was accidentally ran that changed file ownership for a cPanel account Another common reason that you'll need to fix permissions on a site is because of a bad command that was run on an account. If a user mis-typed a chown or chmod command they could accidentally change all of the permissions or ownerships, breaking their website and email accounts. There are two ways this can be easily resolved: -restore the account from a recent backup using the WHM >>
You would just need to change the "cpanel_username" in that example above to the actual cPanel user you are working with. NOTE: NOTE: cPanel Technical Support cannot provide assistance with the above or any other custom commands. The example given above is provided as a courtesy to system administrators, you should be sure to understand any commands before executing them on a live system. Restoring the account from a backup is still the safest method to get things working properly. Example 3 - Ownership was changed on the entire /home directory If a command was executed on the system that changed the ownership of everything in the /home directory, this is a bit more tricky to restore from and will require assistance from an admin familiar with fixing Linux permissions. If your /home directory is on its own partition that will allow you to avoid the security issues presented by
This command sorts through each user, fixes the ownership, and reports the presence of any hard links that need to be manually dealt with. Example 4 - A command changed ownership or permissions across the entire server Unfortunately, this is one scenario that can't be easily recovered from. Since every file on the machine has been modified there is not a reliable way to fix the system. The best thing to do in this case would be to create a new server with a fresh install of cPanel and restore your sites from backups. Conclusion I hope this guide has given you more inside into permissions and how they relate to typical system administration duties. If you have any other questions you can always visit our Technical Support Team and we'll be happy to help!
- owner " this is the owner of the file. Changes made to ownership permissions will not impact other users.
- group " this is the group the file is assigned to. Just as with changes to the "owner" permissions, these only apply to the group that has been assigned to the file or directory.
- all users " these are permissions set for all the other users on the machine that are not the owner or in the group.
- This is a file and not a directory. The first bit of the permissions string is "-" which indicates this is a normal file. If this were the "d" it would indicate we are looking at a directory.
- The permissions are 644. The "-rw-r--r--" is a text representation of the permissions, where "r" "w" and "x" stand for "read" "write" and "execute"
- It is owned by the "cptest" user.
- It is assigned to the cptest group.
- The owner of the file, cptest, can read, write, or remove that file. (this is the first "rw-" portion of the permissions)
- Any user in the cptest group can read the contents of the file, but can not edit or remove it. (This is the second block of "r--")
- All other users on the system can read the contents of the file but can not edit or remove it. (The third and final set of permissions, "r--")
chown cptest:cptest installer.phpThis command changes the owner and the group, represented by the user:group portion of the command, to be the cptest user. After running that, we'll see this is now assigned to that cptest user when we check the file again: Since that file has 644 permissions already, and is now owned by the cptest user, they can visit that PHP page in a browser to start the installation. Although we didn't need to change permissions in this example, here is the command we would have needed to change the permissions to 644, the standard permissions for a PHP file, just so you have it for reference:
chmod 644 installer.phpExample 2 - A command was accidentally ran that changed file ownership for a cPanel account Another common reason that you'll need to fix permissions on a site is because of a bad command that was run on an account. If a user mis-typed a chown or chmod command they could accidentally change all of the permissions or ownerships, breaking their website and email accounts. There are two ways this can be easily resolved: -restore the account from a recent backup using the WHM >>
You would just need to change the "cpanel_username" in that example above to the actual cPanel user you are working with. NOTE: NOTE: cPanel Technical Support cannot provide assistance with the above or any other custom commands. The example given above is provided as a courtesy to system administrators, you should be sure to understand any commands before executing them on a live system. Restoring the account from a backup is still the safest method to get things working properly. Example 3 - Ownership was changed on the entire /home directory If a command was executed on the system that changed the ownership of everything in the /home directory, this is a bit more tricky to restore from and will require assistance from an admin familiar with fixing Linux permissions. If your /home directory is on its own partition that will allow you to avoid the security issues presented by
This command sorts through each user, fixes the ownership, and reports the presence of any hard links that need to be manually dealt with. Example 4 - A command changed ownership or permissions across the entire server Unfortunately, this is one scenario that can't be easily recovered from. Since every file on the machine has been modified there is not a reliable way to fix the system. The best thing to do in this case would be to create a new server with a fresh install of cPanel and restore your sites from backups. Conclusion I hope this guide has given you more inside into permissions and how they relate to typical system administration duties. If you have any other questions you can always visit our Technical Support Team and we'll be happy to help!
Please sign in to leave a comment.
Comments
0 comments