{ "id": "file-permissions", "title": "File Ownership & Permissions", "category": "sysadmin", "tags": ["chown", "chmod", "permissions", "ownership", "ls"], "updated": "2025-10-07", "summary": "Understanding and fixing file ownership and permission bits.", "sections": [ { "heading": "Reading the Permission String", "body": "

Run ls -l to see permissions. The first column looks like -rwxr-xr--.

r=4, w=2, x=1. Add them up for octal notation: rwx=7, rw-=6, r--=4.

" }, { "heading": "chown — Changing Ownership", "body": "

Change the owner and/or group of a file or directory.

", "code": "chown user file # change owner only\nchown user:group file # change owner and group\nchown :group file # change group only\n\n# Recursive — change everything under a directory\nchown -R user:group /path/to/dir" }, { "heading": "chmod — Changing Permissions", "body": "", "code": "chmod 644 file.txt # rw-r--r-- (typical for files)\nchmod 755 /usr/local/bin/app # rwxr-xr-x (typical for executables)\nchmod 700 ~/.ssh # rwx------ (private directory)\nchmod 600 ~/.ssh/authorized_keys # rw------- (private file)\n\n# Recursive\nchmod -R 755 /var/www/html\n\n# Symbolic form (add execute for owner only)\nchmod u+x script.sh" }, { "heading": "Common Patterns", "body": "
ModeNumericTypical use
rw-r--r--644Regular files, config files
rwxr-xr-x755Directories, executables
rwx------700Private directories (e.g. ~/.ssh)
rw-------600Private files (e.g. private keys, authorized_keys)
rwxrwxr-x775Shared directories where the group needs write access
" }, { "heading": "Checking Who Owns What", "body": "", "code": "ls -la /var/www/html # list with ownership\nstat file.txt # detailed file metadata\nfind /path -user root # find files owned by root\nfind /path -not -user deploy # find files NOT owned by deploy" }, { "heading": "A Note on Recursive chown", "body": "

When you run chown -R, it changes everything under the path—including files and subdirectories that may have intentionally different ownership. Know what you are targeting before running it on a live system. Check with ls -laR or find first.

" } ] }