The chmod command
change file mode bits 24 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.
Options in the examples
-R, --recursive- change files and directories recursively
Examples
chmod 755 script.shrwxr-xr-x
chmod 644 file.txtrw-r--r--
chmod 600 private.txtrw-------
chmod 777 public/rwxrwxrwx (dangerous!)
chmod +x script.shAdd execute for all
chmod u+x script.shAdd execute for owner only
chmod go-w file.txtRemove write from group and others
chmod a=r file.txtSet read-only for everyone
chmod u+x,go-x script.shMultiple changes
chmod -R 755 directory/Apply to all files inside
chmod +x myscript.sh
chmod 4755 fileSetuid bit
chmod 2755 fileSetgid bit
chmod 1755 dirSticky bit
sudo chmod -R 755 /var/www/html/
sudo chmod 600 /var/www/html/secret.html
chmod +x ~/scripts/backup.shAllow it to run
chmod 600 suspicious-fileRestrict a file to owner-only
sudo chmod 640 FILEOwner read/write, group read, others nothing
chmod 600 ~/.ssh/configOnly you may write the config
chmod 600 ~/.ssh/id_ed25519Only you may read the private key
chmod 700 ~/.sshThe folder itself: yours alone
sudo chmod 644 FILErw-r--r--: everyone may read, only the owner may write
sudo chmod 755 FOLDERrwxr-xr-x: everyone may enter and list it