🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

chmod Command

Beginner Permissions & Ownership man(1)

Change file and directory permissions

👁 9 views 📅 Updated: Mar 15, 2026
SYNTAX
chmod [OPTION]... MODE FILE...

What Does chmod Do?

chmod (change mode) modifies file and directory permissions. It controls who can read, write, and execute files using either symbolic notation (u+x, g-w) or numeric/octal notation (755, 644).

Linux permissions are organized in three levels: owner (u), group (g), and others (o). Each level has three permission bits: read (r=4), write (w=2), and execute (x=1). chmod changes these permission bits.

chmod is essential for security — setting correct permissions prevents unauthorized access while allowing legitimate users to work. Common patterns: 644 for files (owner read-write, others read), 755 for directories and scripts (owner full, others read-execute).

Options & Flags

OptionDescriptionExample
+x Add execute permission chmod +x script.sh
-R Recursive (apply to all files in directory) chmod -R 755 /var/www/
u+x Add execute for owner only chmod u+x deploy.sh
g+w Add write for group chmod g+w shared_file.txt
o-rwx Remove all permissions for others chmod o-rwx secret.txt
a+r Add read for all (owner, group, others) chmod a+r public.html
--reference Copy permissions from another file chmod --reference=template.sh new_script.sh

Practical Examples

#1 Make script executable

Adds execute permission for all users.
$ chmod +x deploy.sh

#2 Standard file permissions

Owner: read-write (6). Group: read (4). Others: read (4).
$ chmod 644 config.php

#3 Standard directory permissions

Owner: full (7). Group: read-execute (5). Others: read-execute (5).
$ chmod 755 /var/www/html/

#4 Private file

Only owner can read and write. No access for anyone else. Required for SSH keys.
$ chmod 600 ~/.ssh/id_rsa

#5 Recursive web directory

Sets directories to 755 and files to 644 — standard web server permissions.
$ find /var/www -type d -exec chmod 755 {} \; && find /var/www -type f -exec chmod 644 {} \;

#6 Set setgid on directory

New files inherit the directory group. Essential for shared project directories.
$ chmod g+s /shared/project/

#7 Remove all permissions for others

Recursively removes all access for "others" from a private directory.
$ chmod -R o-rwx /home/user/private/

#8 Symbolic notation

Sets exact permissions using symbolic notation. Equivalent to 754.
$ chmod u=rwx,g=rx,o=r file.txt

Tips & Best Practices

Common permission numbers: 644 = files (rw-r--r--). 755 = directories/scripts (rwxr-xr-x). 600 = private files (rw-------). 700 = private directories.
Never chmod 777: chmod 777 gives everyone full access including write. This is a security risk. Use specific permissions instead.
setuid, setgid, sticky bit: Special bits: setuid (4xxx) runs as file owner. setgid (2xxx) inherits group. Sticky bit (1xxx) prevents deletion by non-owners (/tmp).

Frequently Asked Questions

How do I make a file executable?
chmod +x filename. Or chmod 755 filename for full owner permissions with read-execute for others.
What does 644 mean?
6=owner (read+write), 4=group (read), 4=others (read). The most common permission for regular files.
How do I set permissions recursively?
chmod -R 755 dir/ sets everything to 755. Better: find dir -type d -exec chmod 755 {} \; for directories and find dir -type f -exec chmod 644 {} \; for files.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →