What does chmod do?
chmod changes who can read (r=4), write (w=2) and execute (x=1) a file, for the owner, the group and everyone else. chmod 755 = rwxr-xr-x.
chmod [mode] file…
Most useful options
| Option | What it does |
|---|---|
| +x | add execute permission |
| u / g / o / a | user, group, others, all |
| 755 | rwx for owner, r-x for others (scripts, folders) |
| 644 | rw for owner, r for others (normal files) |
| 600 | only the owner can read and write (private keys) |
| -R | apply to a folder and everything inside |
chmod examples
In security work
chmod 777 is almost always a mistake: anyone can change the file. World-writable scripts run by root are a classic privilege escalation.
Questions about chmod
What does chmod 755 mean?
Owner: read+write+execute (7). Group and others: read+execute (5).
What does chmod +x do?
It adds execute permission so the file can be run as a program.