{"id":57565,"date":"2020-09-29T10:43:41","date_gmt":"2020-09-29T15:43:41","guid":{"rendered":"https:\/\/blog.cpanel.com\/?p=57565"},"modified":"2020-09-29T10:43:41","modified_gmt":"2020-09-29T15:43:41","slug":"how-to-assign-permissions-to-files-and-folders-in-cpanel","status":"publish","type":"post","link":"https:\/\/devel.www.cpanel.net\/blog\/tips-and-tricks\/how-to-assign-permissions-to-files-and-folders-in-cpanel\/","title":{"rendered":"How to Assign Permissions to Files and Folders in cPanel"},"content":{"rendered":"\n
File permissions are one of your server\u2019s most important security features. They give you fine-grained control over who can read, write, and execute files. Without them, it would be impossible to safely host multiple users\u2019 websites and data.<\/p>\n\n\n\n
However, incorrect permissions often cause hard-to-diagnose issues. If a website doesn\u2019t load properly or software crashes, there\u2019s a good chance misconfigured permissions are the culprit. They can also be challenging to manage with chmod<\/em>, the standard Linux permission management tool.<\/p>\n\n\n\n In this article, we explain what permissions are and how they work, before showing you how simple it is to assign them in cPanel. <\/p>\n\n\n\n Every file and folder on your server has a set of permissions. One way to see them is on the command line with the ls<\/em> command. <\/p>\n\n\n\n The -l <\/em>option tells ls <\/em>to display a detailed listing with extra information.<\/p>\n\n\n\n We\u2019re interested in the first, third, and fourth columns. The second column shows how many links a file has, which isn\u2019t related to permissions. <\/p>\n\n\n\n Before we get to the permissions, let\u2019s look at the owner and group columns. The meaning of \u201cowner\u201d is straightforward: It\u2019s the user who owns the file; in this case, user1<\/em>.<\/p>\n\n\n\n Files also have an associated group. Groups are collections of users, and they\u2019re useful for managing the permissions of multiple users at once. Here the group is also called user1<\/em>. Every user has a group, and when they create a file, permissions are automatically granted to its members. <\/p>\n\n\n\n Now, let\u2019s zoom in even further and look at the permissions themselves. <\/p>\n\n\n\n The leftmost letter indicates the filetype. Here it\u2019s a d <\/em>so we know the file is a directory. If it was a normal file there would be a dash (-) in this column, as you can see in the first image. <\/p>\n\n\n\n Next, there are three groups of three letters. These indicate read (r), write (w), and execute (x) for the owner, the group, and others. Others, sometimes called \u201cthe world,\u201d means every account on the server that isn\u2019t the user and isn\u2019t in the group. <\/p>\n\n\n\n In our example, all three can read, write, and execute the file, but you will rarely see this on a server because it\u2019s prudent to limit access, especially for the other<\/em> category. <\/p>\n\n\n\n Let\u2019s say you want the owner and group members to read and write the file, but only allow other users to read it. We\u2019ll show you an easier way to do this in cPanel in a moment, but for now, we\u2019ll use chmod<\/em>, a command-line tool for managing permissions. <\/em><\/p>\n\n\n\n To tell chmod <\/em>what to change, we use plus (+) to add permissions and minus (-) to remove them. We also tell it to whom the changes should apply: o for the owner, g for the group, o for others, and a for everyone. <\/p>\n\n\n\n The first command tells chmod <\/em>to remove write (w) and execute (x) from all users. The second then adds write permissions back to the owner and group. The file\u2019s permissions now look like this:<\/p>\n\n\n\n The dashes are used to indicate the lack of a particular permission. <\/p>\n\n\n\n There is another way to tell chmod <\/em>which permissions to use, and it\u2019s often easier to understand, which is why we use it in cPanel\u2019s File Manager. <\/em><\/p>\n\n\n\n Instead of a letter, we use a number:<\/p>\n\n\n\n To set permissions, the numbers are simply added together. For example, to set read (4) and write (2), we\u2019d use 6. To achieve the same permissions as in the previous example, we\u2019d use the following command:<\/p>\n\n\n\n That\u2019s 6 (read plus write) for the owner and group, and 4 (read-only) for others. To give the same permissions to the group and others, but also allow the owner to execute the file, we\u2019d use:<\/p>\n\n\n\n To indicate read, write, and execute we add 4, 2, and 1 for a total of 7. <\/p>\n\n\n\n If you\u2019re wondering why those particular numbers were chosen, it\u2019s because 7 is the octal (base-8) representation of the binary 111. We\u2019re telling chmod <\/em>which bits to set for read (100), write (010), and execute (001). <\/p>\n\n\n\n There is one last wrinkle to understand: what do read and execute mean for a directory? After all, you can execute a file with code in it, but you can\u2019t execute a directory. <\/p>\n\n\n\n In fact, the permissions have a different meaning when applied to a directory:<\/p>\n\n\n\n cPanel provides an easy-to-use interface for setting file permissions within the File Manager. <\/em>Open File Manager<\/em>, which you will find in the Files<\/em> section of the main page. <\/p>\n\n\n\n File permissions are displayed in the rightmost column of the File Manager, <\/em>using the numerical notation.<\/p>\n\n\n\n To change them, select a file and click Permissions <\/em>in the menu bar.<\/p>\n\n\n\n Setting new permissions for the user, group, and world (others) is as simple as checking and unchecking read, write, and execute. As you make changes, they are reflected in the box at the bottom, but they won\u2019t be applied until you confirm by clicking Change Permissions. <\/em><\/p>\n\n\n\n File permissions are an essential component of server security, especially on shared hosting servers with many users. Setting the wrong permissions can break software and open you to dangerous vulnerabilities, so it\u2019s worth taking time to understand how they work. With cPanel & WHM\u2019s intuitive interface, permission management is a breeze. <\/p>\n\n\n\n As always, if you have any feedback or comments, please let us know. We are here to help in the best ways we can. You\u2019ll find us on Discord<\/a>, the cPanel forums<\/a>, and Reddit<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":" File permissions are one of your server\u2019s most important security features. They give you fine-grained control over who can read, write, and execute files. Without them, it would be impossible to safely host multiple users\u2019 websites and data. However, incorrect permissions often cause hard-to-diagnose issues. If a website doesn\u2019t load properly or software crashes, there\u2019s […]<\/p>\n","protected":false},"author":77,"featured_media":65529,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[61],"tags":[],"class_list":["post-57565","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips-and-tricks"],"acf":[],"yoast_head":"\nFile Permission Settings<\/strong><\/h2>\n\n\n\n
ls -l<\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
Changing File Permissions with Chmod<\/strong><\/h3>\n\n\n\n
chmod a-wx example.html\nchmod og+w example.html<\/code><\/pre>\n\n\n\n
-rw-rw-r--<\/code><\/pre>\n\n\n\n
File Permissions with Numbers<\/strong><\/h3>\n\n\n\n
chmod 664 example.html<\/code><\/pre>\n\n\n\n
chmod 764 example.html<\/code><\/pre>\n\n\n\n
File Permissions for Directories<\/strong><\/h2>\n\n\n\n
How to Assign Permissions to Files and Folders With File Manager<\/strong><\/h2>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n