chmod 777 Launch!
Original Text
This article is transcoded by SimpRead, original URL www.runoob.com Shell File Inclusion Nginx Installation and Configuration
Linux chmod (full English: change mode) command is used to control user permissions to files.
In Linux/Unix, file access permissions are divided into three levels: file owner (Owner), user group (Group), and other users (Other Users).
![]()
Only the file owner and superuser can modify the permissions of files or directories. Permissions can be specified using absolute mode (octal numeric mode) or symbolic mode.
![]()
Usage permissions: all users
Syntax
chmod [-cfvR] [--help] [--version] mode file...
Parameter Description
mode: permission setting string, format as follows:
[ugoa...][[+-=][rwxX]...][,...]
Where:
- u represents the file owner, g represents the group to which the file owner belongs, o represents others besides these, a means all three.
-
- means add permission, - means remove permission, = means set permission exactly.
- r means readable, w means writable, x means executable, X means executable only if the file is a directory or already has execute permission set.
Other parameters:
- -c: only show changes if permission is actually modified
- -f: do not show error messages if permission cannot be changed
- -v: show detailed information about permission changes
- -R: apply changes recursively to all files and subdirectories in the current directory
- –help: display help information
- –version: display version
Symbolic Mode
Symbolic mode allows setting multiple items: who (user type), operator, and permission, where each item can be separated by commas. The chmod command modifies the access permissions of the specified user type(s) on a file. User types are represented by one or more letters in the ‘who’ position, as shown in the symbolic mode table for who:
| who | User Type | Description |
|---|---|---|
| u | user | file owner |
| g | group | file owner's group |
| o | others | all other users |
| a | all | all users, equivalent to ugo |
Operator symbols:
| Operator | Description |
|---|---|
| + | add permission for specified user type |
| - | remove permission for specified user type |
| = | set permission for specified user type, resetting all permissions |
Permission symbols:
| Symbol | Name | Description |
|---|---|---|
| r | read | set read permission |
| w | write | set write permission |
| x | execute | set execute permission |
| X | special execute | execute permission if file is directory or if other execute bit set |
| s | setuid/gid | set setuid or setgid bit depending on user type specified |
| t | sticky bit | set sticky bit, only superuser can set, only file owner (u) can use it |
Octal Syntax
The chmod command can use octal numbers to specify permissions. File or directory permissions are controlled by 9 permission bits grouped into three sets: user (owner) read, write, execute; group read, write, execute; others read, write, execute. Historically, file permissions were stored in bit masks where bits set to 1 indicate the corresponding permission.
| # | Permission | rwx | Binary |
|---|---|---|---|
| 7 | read + write + execute | rwx | 111 |
| 6 | read + write | rw- | 110 |
| 5 | read + execute | r-x | 101 |
| 4 | read only | r-- | 100 |
| 3 | write + execute | -wx | 011 |
| 2 | write only | -w- | 010 |
| 1 | execute only | --x | 001 |
| 0 | none | --- | 000 |
For example, 765 can be interpreted as:
- Owner permissions number: sum of owner’s three permission bits. For rwx, 4+2+1 = 7.
- Group permissions number: sum of group permission bits. For rw-, 4+2+0 = 6.
- Others permissions number: sum of others permission bits. For r-x, 4+0+1 = 5.
Examples
Set file file1.txt to be readable by everyone:
chmod ugo+r file1.txt
Set file file1.txt to be readable by everyone:
chmod a+r file1.txt
Set file1.txt and file2.txt so that owner and group have write permission, but others don’t:
chmod ug+w,o-w file1.txt file2.txt
Add execute permission to owner of ex1.py:
chmod u+x ex1.py
Set all files and subdirectories in current directory readable by everyone:
chmod -R a+r *
chmod can also use numbers to represent permissions, e.g.:
chmod 777 file
Syntax:
chmod abc file
Where a, b, c each represent a number for User, Group, and Other permissions respectively.
r=4, w=2, x=1
- For rwx attribute: 4+2+1=7;
- For rw- attribute: 4+2=6;
- For r-x attribute: 4+1=5.
chmod a=rwx file
and
chmod 777 file
have the same effect.
chmod ug=rwx,o=x file
and
chmod 771 file
have the same effect.
Using chmod 4755 filename can make the program have root permissions.
More Descriptions
| Command | Description |
|---|---|
| chmod a+r file | Add read permission for all users on file |
| chmod a-x file | Remove execute permission from all users on file |
| chmod a+rw file | Add read and write permissions for all users on file |
| chmod +rwx file | Add read, write, execute permissions for all users on file |
| chmod u=rw,go= file | Set read and write permissions for file owner, clear all permissions for group and others (space means no permissions) |
| chmod -R u+r,go-r docs | Add read permission for user and remove read permission for group and others on directory docs and all files/subdirectories recursively |
| chmod 664 file | Set read and write permission for file owner and group, and read permission for others |
| chmod 0755 file | Equivalent to u=rwx (4+2+1),go=rx (4+1 & 4+1). No special mode (0) |
| chmod 4755 file | 4 sets the setuid bit, remaining permissions are u=rwx (4+2+1),go=rx (4+1 & 4+1). |
| find path/ -type d -exec chmod a-x {} \; | Remove execute permission for all users on path/ and all its directories (not files). Use '-type f' to match files |
| find path/ -type d -exec chmod a+x {} \; | Allow all users to traverse or access the directory path/ |