Linux permissions control who can read, write, or execute files. Ownership is split between a user and a group. Here’s how to read permission bits, change them, and save time with aliases.
Permission basics (rwx)
- Three sets: owner, group, others.
- Bits: r=read, w=write, x=execute.
- Example:
-rw-r--r--→ owner can read/write; group and others can read. - Directories:
xmeans you can enter/traverse;rmeans you can list;wmeans you can create/delete inside.
chmod: change permissions
- Numeric: r=4, w=2, x=1. Sum per class.
chmod 644 file # -rw-r--r-- chmod 755 script.sh # -rwxr-xr-x chmod 700 secret # -rwx------ - Symbolic:
[ugoa][+-=][rwx]chmod u+x script.sh # add execute to owner chmod go-w file # remove write for group/others chmod a+r docs.txt # add read for all chmod -R 755 dir # recursive
Ownership: chown and chgrp
- chown user:group target
sudo chown alice:developers app.log sudo chown -R www-data:www-data /var/www - chgrp group target (change only group)
sudo chgrp developers shared.txt - Check current ownership/permissions:
ls -l
Special bits (quick note)
- setuid (4xxx): Run with owner’s UID (used by some system binaries).
- setgid (2xxx): On directories, new files inherit group.
- sticky (1xxx): On dirs (e.g., /tmp), only owners can delete their files.
Alias: shortcuts for common commands
- Temporary alias (current shell):
alias ll='ls -lah' - Add to shell rc (~/.bashrc, ~/.zshrc) for persistence.
- Examples:
alias ll='ls -lah --color=auto' alias gs='git status' alias cpr='cp -r' alias chmodx='chmod +x' - View aliases:
alias· remove:unalias name
Good practices
- Grant minimum needed permissions; avoid 777.
- Use groups for shared access instead of loosening “others.”
- Set group ownership and setgid on shared dirs so files inherit the shared group.
- Keep scripts executable only where needed; be explicit with chmod in CI.
With chmod, chown, and chgrp you control access; aliases make repeated tasks faster. Always aim for least privilege and clear ownership.