chmod
Change who may read, write or run a file
What it does
Every file has three sets of permissions: for the owner (u), the group (g) and everyone else (o). The permissions are read (r), write (w) and execute (x); for a folder, x means the right to enter it. ls -l shows them: -rwxr-xr-x reads in groups of three.
You set permissions with letters (+x, g+w, o-r) or with a three-digit number for the owner, the group and everyone else, where read = 4, write = 2 and execute = 1. So 644 is a regular file, 755 a script or a folder, 600 the owner only. -R changes a folder and everything inside.
Careful. chmod -R 777 lets everyone read, write and run everything, which is how security holes appear. SSH, by the way, refuses a key that anyone but its owner can read.
Syntax
chmod +x <file>
chmod <mode> <file>
chmod -R <mode> <folder>Examples
Allow the script deploy.sh to run
chmod +x deploy.shchmod— change permissions+x— add the execute permissiondeploy.sh— the file
Leave the key ~/.ssh/id_ed25519 readable and writable by its owner only
chmod 600 ~/.ssh/id_ed25519same as:
chmod u=rw,go= ~/.ssh/id_ed25519chmod— change permissions600— owner: read and write, everyone else: nothing~/.ssh/id_ed25519— the private SSH key
Let the group write to the folder shared and everything inside
chmod -R g+w sharedsame as:
chmod --recursive g+w shared-R— recursively, with everything insideg+w— for the group (g) add (+) write (w)shared— the folder