Hostwinds Tutorials
Search results for:
Table of Contents
Tags: cPanel
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.
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 select the File or Folder for 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 are required, you can finish and save the changes by clicking on the Change Permissions button.
If you are using a different control panel that does not have the permissions support or doesn't have any control panel at all, you can change the permissions of a File or Folder directly from the command line. This will be done using the chmod command. This command is potent because it can break certain functions that rely on the file permissions that you are changing. User discretion is advised.
Log into your server via SSH, or access the command line.
Once logged in, you will want to navigate 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 below will move into the documents folder inside the user _myuser_'s home directory.:
cd /home/myuser/documents
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 want to set, and name with the name of the file or folder:
chmod permissions name
Example:
chmod 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 before 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.
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.
Example:
chmod -R 644 test
This command will change the permissions of all files and folders located within the folder named test to be 644. The owner would 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 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 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.[
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 the user with the new file owner and group with the new group for the file. Name is the name of the file or folder to change ownership for. Suppose 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.
Example:
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.
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 filegroup. 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 folder or file name. 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 look at the manual pages for these commands. These can be accessed by typing man (stands for manual) plus the command afterward. For example,
man chmod
If you should have any questions or would like assistance, please contact us through Live Chat or by submitting a ticket with our Technical Support team.
Written by Hostwinds Team / May 28, 2018