chmod (change mode) sets the read, write, and execute permissions for files and directories. You can use numeric (octal) notation for precision or symbolic notation for readability. Understanding chmod is fundamental for Linux system administration and secure file management.
LinuxchmodPermissionsCLIchmod 644 filename.txt
chmod 755 script.sh
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
chmod u+x script.sh
u (user/owner), g (group), o (others), a (all). Operators: + (add), - (remove), = (set exactly). This adds execute permission only for the owner without changing other permissions.chmod a+x script.sh
a target applies the change to all three classes (user, group, others) simultaneously. This makes the file executable by everyone on the system — commonly used for public utility scripts.chmod go-w filename.txt
go means group and others. This removes write permission from both simultaneously. Useful for hardening config files that were accidentally made world-writable.chmod -R 755 /var/www/html/
-R flag applies the permission change recursively to all files and subdirectories. Use with caution — this sets the same permissions on both files and directories, which is often incorrect (files shouldn't be executable by default).find /var/www -type f -exec chmod 644 {} \;
chmod -R: uses find to target only regular files. Combine with a second find command for directories to set different permissions for each type — 644 for files, 755 for directories.find /var/www -type d -exec chmod 755 {} \;
ls -la to view current permissions before changing them.u/g/o/a with +/-/= and r/w/x.The three digits in numeric mode represent: owner, group, and others (world). Each digit is the sum of: read (4) + write (2) + execute (1). So 7 = rwx, 6 = rw-, 5 = r-x, 4 = r--. For example, 755 = rwxr-xr-x.
chmod changes the permission bits (what users can do with a file). chown changes the ownership of a file (which user and group own it). Both together control file access: ownership determines which user/group the permission bits apply to.
chmod 777 gives read, write, and execute permission to everyone on the system, including malicious users. It is especially dangerous for web-accessible files and directories. Always use the minimum permissions necessary: 644 for files, 755 for directories, 600 for private keys.