Knowledge base
1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!
Understanding CHMOD (file permissions on a server)
This guide details CHMOD (short for change mode), which allows you to change the access permissions of a file or directory.
Modify FTP permissions
The permissions available for each user/group are as follows (see this other Wikipedia guide):
- read: grants the right to list (also requires execute permission) and read within a directory and/or read a file.
- write: grants the right to create, modify, rename, and delete files and/or directories
- execute: for a directory: grants the right to access it to read its subdirectories -> For a file: grants the right to execute it if it is a program or script, for example.
- set uid (?): for a file with execution rights, this will cause it to be executed with the rights of the owner if it uses the execve or setuid system call.
- set gid (?): all new files created will belong to the group of the directory, and for a file with execution rights, this will cause it to be executed with the rights of the group.
- sticky bit (?): on a directory, files within the directory can only be renamed or deleted by the owner, even if other users have write permissions. This permission is not very useful for files.
The Web FTP in the Manager allows you to change file permissions (including the permissions for /web).
Most FTP software/clients allow you to change file access permissions; this function is usually called "CHMOD" and can be found under "Properties," "Permissions," or "Attributes" (usually by right-clicking on the file or folder to be modified). A checkbox often allows you to apply the permissions to all subdirectories and files in the folder, in recursive mode.
Once you have checked the permissions you want, validate them, and the rights will be modified, except for those you do not have permission to modify, or rather, that the user under which you are logged in does not have the right to modify.
Learn more
When we talk about changing permissions, it usually involves using a command like "chmod 777", "chmod 666", or something similar. This involves three digits, where:
- the first corresponds to the owner's permissions
- the second corresponds to the group's rights
- the third number corresponds to the rights of other users.
And the permissions are broken down as follows:
- "4" for read permission
- "2" for write permission
- "1" for execute permission
You simply need to add these numbers together. For example, if you want all rights for the owner but no rights for others, you would use "chmod 700" (4 + 2 + 1 = 7). If you only want read and write permissions for everyone (4 + 2 = 6), you would use "chmod 666".
These values are known to all good FTP software/clients, so you will be able to directly enter the number in your software/client to change the permissions.
To change the permissions on files or directories in PHP, you can also do so using the “chmod” function, as in the following example:
chmod ("/a_folder/a_file", 0755)Note that the value to be applied must be in octal format, hence the mandatory leading zero. Be careful if you store the value in a variable, as you will encounter a data type issue, which you can circumvent using the octdec() function, as in the following example:
$mode = 0755;chmod("a_folder/a_file", octdec($mode))Link to this FAQ: https://faq.infomaniak.com/111
Has this FAQ been helpful?