{ "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--.
- file, d directory, l symlinkr=4, w=2, x=1. Add them up for octal notation: rwx=7, rw-=6, r--=4.
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": "| Mode | Numeric | Typical use |
|---|---|---|
rw-r--r-- | 644 | Regular files, config files |
rwxr-xr-x | 755 | Directories, executables |
rwx------ | 700 | Private directories (e.g. ~/.ssh) |
rw------- | 600 | Private files (e.g. private keys, authorized_keys) |
rwxrwxr-x | 775 | Shared directories where the group needs write access |
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.