Changing File Permissions in cPanel

Changing File Permissions in cPanel

File Permission settings in cPanel

One of your server’s most crucial security features is file permissions. But don’t worry there are many ways for changing file permission in cPanel which let you regulate who may read, write, and execute files at a finer level. It would be difficult to properly host many users’ websites and data without them.

Incorrect permissions, on the other hand, frequently produce difficult-to-diagnose problems. If a website fails to load or software breaks, it’s likely that improper permissions are to blame. They can also be difficult to control with chmod, the typical Linux permissions manager.

We’ll go over what permissions are and how they function in this post before showing you how easy it is to apply them in cPanel. Here is the following ways for changing file permission in cPanel.

File Permission Settings

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 command.

ls -l

The -l option tells ls to display a detailed listing with extra information.

1 4

The first, third, and fourth columns are of particular importance to us. The second column shows how many links a file has, which isn’t related to permissions.

2 4

Let’s take a look at the owner and group columns before moving on to permissions. The definition of “owner” is simple: The file is owned by the user; in this example, user1.

A group is also related to a file. Groups are groups of users that may be used to manage many users’ permissions at once. User1 is also the name of the group in this case. Every user has a group, and rights are automatically assigned to its members when they create a file.

Now, let’s zoom in even further and look at the permissions themselves.

3 4

The filetype is indicated by the letter on the left. Because it’s a d, we know it’s a directory. This column would have a dash (-) in it if it were a normal file, as seen in the first image.

There are three groups of three letters after that. For the owner, the group, and others, they imply read (r), write (w), and execute (x). Others, also known as “the world,” refers to any account on the server that isn’t the user or a member of the group.

All three can read, write, and execute the file in our example, but you’ll seldom see this on a server because it’s best to restrict access, especially for the other category.

Changing File Permissions with Chmod

Let’s assume you want the file’s owner and group members to be able to read and write it, but you just want other users to be able to read it. We’ll show you a better method to accomplish this in cPanel later, but for now, we’ll use chmod, a command-line tool for managing permissions.

chmod a-wx example.html

chmod og+w example.html

To tell chmod what to change, we use plus (+) to add permissions and minus (-) to remove them to inform chmod what to do. We also specify who should be affected by the changes: o for the owner, g for the group, o for others, and a for everyone.

The first command instructs chmod to remove all users’ write (w) and execute (x) permissions. The second restores the owner’s and group’s write permissions. The permissions of the file now look like this:

-rw-rw-r–

The dashes are used to indicate that a certain permission is not granted.

File Permissions with Numbers

There is a simpler method to inform chmod which rights to use, which is why we use it in the cPanel File Manager. We use a number instead of a letter:

  • No permissions is 0
  • Read is 4
  • Write is 2
  • Execute is 1

The numbers are simply joined together to determine permissions. We use (4) to set read and (2) to write, for example. We’d use the following command to get the same permissions as in the previous example:

chmod 664 example.html

For the owner and group, that’s 6 (read and write), and for the rest, it’s 4 (read-only). To grant the group and others the same rights as the owner but also allowing the owner to execute the file, we’d use:

chmod 764 example.html

To indicate read, write, and execute we add 4, 2, and 1 for a total of 7. 

If you’re wondering why those particular numbers were chosen, it’s because 7 is the octal (base-8) representation of the binary 111. We’re telling chmod which bits to set for read (100), write (010), and execute (001). 

File Permissions for Directories

There’s one last point to grasp: what do the terms “read” and “execute” mean in the context of a directory? After all, you may run a file that contains code but not a directory.

When applied to a directory, the permissions have a different meaning:

  • Read (r or 4) allows users to list files in the directory.
  • Write (w or 2) allows users to create, rename, and delete files in the directory.
  • Execute (x or 1) allows users to access the files and folders the directory contains.

How to Assign Permissions to Files and Folders With File Manager

Within the File Manager, cPanel provides an easy-to-use interface for adjusting file permissions. Open the File Manager, which may be found on the home page under the Files section.

4 5

The number notation is used to display file permissions in the File Manager’s rightmost column.

5 3

To change them, select a file and click Permissions in the menu bar.

6 4

Setting new permissions for the user, group, and world (others) is as simple as checking and unchecking read, write, and execute. Changes are reflected in the box at the bottom as you make them, but they won’t take effect until you confirm by clicking Change Permissions.

File permissions are an important part of server security, particularly on shared hosting servers with a lot of users. It’s worth spending the time to learn how permissions function since they may ruin software and expose you to hazardous risks. With cPanel & WHM simple interface, permission administration is a snap.

If you want to start a new website or a business website, you must first build a good website, so purchase a low-cost domain name and we will also provide the best website development.

Iftikhar Qureshi
Iftikhar Qureshi
IFTIKHAR is a Digital Blogger and SEO Specialist at F60 Host. Using his IT degree and expertise as a website operator, he hopes to share his knowledge with other IT geeks.