-rwxr-xr-x
Quick Presets
Command Output
chmod
755
chmod u=rwx,g=rx,o=rx filename
How chmod Works
In Linux and Unix-like operating systems, the chmod (change mode) command is used to set or modify the access permissions of files and directories. File permissions dictate who can read, write, or execute a specific file.
Permissions are divided into three user classes:
- Owner (u): The user who created or owns the file.
- Group (g): Other users who are members of the file's group.
- Others (o): Everyone else on the system.
Understanding Permission Numbers
Numeric (octal) notation is the most common way to use chmod. Each digit represents a user class (Owner, Group, Others) and is calculated by adding the values of the permissions granted:
| Number | Permission | Symbol | Breakdown |
|---|---|---|---|
| 0 | None | --- | 0 |
| 1 | Execute only | --x | 1 |
| 2 | Write only | -w- | 2 |
| 3 | Write & Execute | -wx | 2 + 1 |
| 4 | Read only | r-- | 4 |
| 5 | Read & Execute | r-x | 4 + 1 |
| 6 | Read & Write | rw- | 4 + 2 |
| 7 | Read, Write & Execute | rwx | 4 + 2 + 1 |
Common chmod Examples
chmod 777 file: Dangerous. Gives read, write, and execute permissions to everyone.chmod 755 script.sh: Common for shell scripts and web directories. The owner can edit and run it; others can only read and run it.chmod 644 config.txt: Common for standard files. The owner can edit it; others can only read it.chmod 600 private.key: Secure. Only the owner can read and write to the file. Used for SSH keys.
Special Permissions
Beyond standard read/write/execute, Linux supports special permissions that prepend a fourth digit (e.g., 4755):
- setuid (4): Executable runs with the permissions of the file owner, rather than the user running it.
- setgid (2): Executable runs with group permissions, or new files in a directory inherit the directory's group.
- Sticky bit (1): Used on directories (like
/tmp) to prevent users from deleting files owned by others.