Linux Command: chmod
Change file and directory permissions
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).
Syntax
chmod [OPTION]... MODE FILE...Key Options
+xโ Add execute permission-Rโ Recursive (apply to all files in directory)u+xโ Add execute for owner onlyg+wโ Add write for groupo-rwxโ Remove all permissions for othersa+rโ Add read for all (owner, group, others)
Examples
Make script executable
chmod +x deploy.shStandard file permissions
chmod 644 config.phpStandard directory permissions
chmod 755 /var/www/html/Pro Tips
- 644 = files (rw-r--r--). 755 = directories/scripts (rwxr-xr-x). 600 = private files (rw-------). 700 = private directories.
- chmod 777 gives everyone full access including write. This is a security risk. Use specific permissions instead.
- Special bits: setuid (4xxx) runs as file owner. setgid (2xxx) inherits group. Sticky bit (1xxx) prevents deletion by non-owners (/tmp).
Learn more: Full chmod reference โ