When working with Linux, there may come a time where you will need to modify file or folder permissions due to a 403 error on your Website, or for a certain script or program to run properly. This can either be done using cPanel’s File Manager, which makes this an easy process or directly from the command line, for those who don’t have cPanel. As always, before making changes to your files and folders, we highly suggest taking a local backup to your computer so that it can easily be restored.
How To Change Permissions With cPanel
- Log into your cPanel.
- Once logged in, navigate to find the File Manager icon. This will be within the Files section, by default towards the top.
- From the File Manager you will be able to select the File or Folder of which you want to change the permissions for. After clicking on the File / Folder, you will want to click on the Permissions link at the top of the File Manager. You can also view under the Permissions column of the File Manager, the current permissions that the File / Folder has.
- Clicking that link will open up a new Change Permissions dialog menu to choose the permissions from. Here you can easily set the permissions that you want to use for that particular file or folder.
- Once you set the permissions that you want or that are required, you can finish and save the changes by clicking on the Change Permissions button.
How To Change Permissions In Command Line
If you are using a different control panel that does not have the permissions support or if you don’t have any control panel at all, you’re able to change the permissions of a File or Folder directly from the command line. This will be done using the chmod command. This command is very powerful, in that it can break certain functions that rely on the files permissions that you are changing. User discretion is advised.
Changing Single File / Folder Permissions
- Log into your server via SSH, or access the command line.
- Once logged in, you will want to navigate to the file or folder that you are changing the permissions for. This can be done through the use of the cd command. This will change the current directory to whatever directory is specified after the command. Example: cd /home/myuser/documents will move into the documents folder inside of the user myuser‘s home directory.
- Once in the desired directory (the pwd command will print the correct working directory) you will want to enter in the following command, replacing
permissions with the permissions that you are wanting to set, and name with the name of the file or folder:
1chmod permissions name
Example:1chmod 744 test
This will change the permissions of the file (or folder) named test to be 744 meaning everyone can read write and execute that file.
Changing permissions to 777 is strongly discouraged.
Using a command such as pwd prior to using the chmod command will ensure you are working in the correct directory and working with the intended files and folders in the correct location
- Entering in that command should produce no message, unless something had gone wrong. If nothing is displayed, the permissions should now be changed. You can view the permissions for the files in your current directory with the ls -l command.
Changing Permissions Recursively
The following should be used with extreme caution. We strongly encourage you to take a backup of your files before proceeding.
If you want to change the permissions for all files and folders within a directory, this can easily be done by adding an argument to the above command. This is done with the -R argument.
chmod -R 644 test
This command will change the permissions of all files and folders located within the folder named test, to be 644. Meaning the owner would be able to read and write to the file / folder, but everyone else can only read the files / folders.
When specifying a path to use for the folder, it can be either relative to your current directory location, or absolute (relative to the root of the system ‘/‘). To specify an absolute path, you will want to proceed your path with a forward slash ( / ). Otherwise, the path will be assumed to be relative to your current position.
Make sure that the -R in the command is capitalized, otherwise the command may not work as intended.[
Changing File or Folder Ownership
When changing just the group, it is recommended to use the chgrp command as described below. This will minimize the possibility of something going wrong.
Along with changing the permissions of a file, you may want to change the owner or group of a file or folder. To do this there is a similar command for this, the chown command. The usage of this command is as follows:
chown user:group name
Replace user with the new owner of the file, and group with the new group for the file. Name is the name of the file or folder to change ownership for. If you want to recursively change the ownership of files and folders within a directory. It is similar to how it is done with the chmod command. By adding the -R argument to the command.
chown -R testUser:testGroup test
This will change the ownership of all files and folders within the test directory so that testUser is the owner, and testGroup is the group.
Changing File or Folder Group Ownership
Similar to the chown command, this command can be used either on a single file / folder, or recursively. The command we are referring to is the chgrp command. This command works similar to the chown command, except only this one changes the group of the file. You can use this command like so:
chgrp group name
Replacing group with the group that you are giving permissions on the file for, and name with the name of the folder or file. When executing this will only change the group of the file / folder, not the actual user owner of the file. The -R argument can be used as well with this command.
For more information about the chmod, chown and chgrp commands, it is recommended to take a look at the manual pages for these commands. These can be accessed by typing man (stands for manual) plus the command afterwards. For example, man chmod
- What Are Permissions On Linux? – This article describes what permissions are, and how they are relevant to the Linux system.
If you should have any questions or would like assistance, do feel free to contact us through Live Chat, on our Phones, or by submitting a ticket with our Technical Support team.