Command library / chmod
chmod
Change file permissions
Changes who may read (r), write (w) or execute (x) a file. Permissions are set for three audiences: the owner (u), the group (g) and everyone else (o). In octal mode each audience is one digit — r=4, w=2, x=1 added together — so 755 means rwx for the owner and r-x for the group and others.
Practice chmodUsage
chmod [options] octal-mode file...
Options and flags
modeoctal (755) or symbolic (u+x) permission change
filefile or directory to change
-Rrecursive: apply to a directory and everything inside it
-vverbose: print every file that is changed
Examples
chmod 755 backup.shOwner rwx, everyone else r-x — a normal executable script.
chmod u+x deploy.shAdd execute for the owner only; leave other bits untouched.
chmod 600 ~/.ssh/id_rsaPrivate keys must be readable and writable by the owner only.
chmod -R 750 /opt/toolsOwner rwx, group r-x, others nothing — for a whole tree.
Common mistakes
The mode comes first, then the file.
chmod needs a file to act on.