{"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

File Permission Settings<\/strong><\/h2>\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

ls -l<\/code><\/pre>\n\n\n\n

The -l <\/em>option tells ls <\/em>to display a detailed listing with extra information.<\/p>\n\n\n\n

\"\"<\/figure>\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

\"\"<\/figure>\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

\"\"<\/figure>\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

Changing File Permissions with Chmod<\/strong><\/h3>\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

chmod a-wx example.html\nchmod og+w example.html<\/code><\/pre>\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

-rw-rw-r--<\/code><\/pre>\n\n\n\n

The dashes are used to indicate the lack of a particular permission. <\/p>\n\n\n\n

File Permissions with Numbers<\/strong><\/h3>\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