What does chmod change?
The mode bits of a file or folder: read, write and execute for three classes of people, the owner, the owning group and everyone else. It does not change who the owner is; that is chown, covered in The chown command. Only the file's owner or root can change its mode.
How do numeric modes work?
Each class gets one digit, the sum of its bits: read is 4, write is 2, execute is 1. Three digits give owner, group and others in that order.
| Mode | Letters | Typical use |
|---|---|---|
600 | rw------- | Private keys, .env files, secrets |
640 | rw-r----- | Config files a service group must read |
644 | rw-r--r-- | Public web files, normal documents |
700 | rwx------ | Private folders, personal scripts |
750 | rwxr-x--- | App folders shared with one group |
755 | rwxr-xr-x | Public folders and programs, see chmod 755 explained |
2775 | rwxrwsr-x | Team folder where new files inherit the group |
chmod 640 /etc/myapp/settings.ini chmod 600 /home/ana/.config/rclone/rclone.conf
How do symbolic modes work?
Letters change specific bits and leave the rest alone, which is often safer than setting all of them. The form is who, operator, what: u owner, g group, o others, a all; + add, - remove, = set exactly; r, w, x.
chmod u+x deploy.sh # owner may run it chmod g-w,o-rwx shared/report # group loses write, others lose everything chmod a=r published.txt # read-only for all chmod ug=rw,o= ledger.csv # owner and group read-write, others nothing
Symbolic modes shine when you want to add one bit without knowing the current mode, for example making a downloaded script executable.
What does execute mean on a folder?
Permission to enter it and reach files inside. Read on a folder lets you list names; execute lets you open what is inside by name; write lets you create, rename and delete entries. A folder with r-- lets you see file names but not open the files, a combination that surprises people. Web servers need execute on every folder in the path to a file, all the way from /, which is the most common cause of a "403 Forbidden" after moving a site.
What are setuid, setgid and the sticky bit?
A fourth, leading digit sets three special bits:
- setuid (4000) on a program runs it as the file's owner.
/usr/bin/passwduses it to update the password file. Never set it on your own scripts; Linux ignores it on scripts anyway, and on binaries it is a classic privilege escalation risk. - setgid (2000) on a folder makes new files inherit the folder's group, ideal for team folders. On programs it runs them with the file's group.
- sticky (1000) on a folder lets people delete only their own files, even when the folder is writable by all.
/tmpis1777for this reason.
chmod 2775 /srv/shared/design chmod g+s /srv/shared/design # same setgid bit, symbolic form
Can I copy permissions from another file?
Yes, GNU chmod accepts a reference: chmod --reference=/etc/nginx/nginx.conf /etc/nginx/conf.d/shop.conf. It is handy when adding files to a folder whose mode you want to match without reading it first.
How do I see what changed?
-v reports every file processed and -c reports only real changes:
chmod -c 640 /etc/myapp/*.ini stat -c '%a %A %U:%G %n' /etc/myapp/*.ini
stat prints the numeric and symbolic mode side by side, which makes a quick audit easy to read.
What mistakes should I avoid?
Never "fix" access problems with chmod 777. It lets every account and every compromised process on the machine change the file, and it rarely solves the real issue, which is usually ownership or a missing execute bit on a parent folder. Find who needs access, make them owner or group member, and give the smallest mode that works. Applying modes to whole trees needs care too, since files and folders want different bits; chmod recursively shows how.
Keep Reading
chmod 755 explained
What mode 755 grants, where it belongs on a server, where it does not, and how it compares with 750, 775 and 644.
Openchmod recursively
Change permissions across whole folder trees without breaking them: chmod -R, the capital X trick and find for files versus folders.
OpenLinux file permissions
Read ls -l output, understand owner, group and other bits, umask defaults, ACLs and why root and SELinux sit on top of it all.
OpenThe chown command
Every useful form of chown: owner, group, both, numeric IDs, reference files and the rules about who may change ownership.
OpenFAQ
Quick Answers
Owner can read and write, group and others can only read.
Run chmod u+x followed by the script name, or chmod 755 if everyone may run it.
It allows entering the folder and opening files inside it by name.
On a folder it makes new files inherit the folder's group, which suits shared team folders.
Almost never on a server. Fix ownership or group membership instead and use the smallest mode that works.