Skip to content

Latest commit

Β 

History

History
33 lines (28 loc) Β· 1.25 KB

File metadata and controls

33 lines (28 loc) Β· 1.25 KB

Linux Permissions (Level 1) πŸ”’

Understanding Permissions (ls -l)

Format: drwxr-xr-x

  • d β€” Directory (or - for file).
  • rwx (User/Owner) β€” Read, Write, Execute.
  • r-x (Group) β€” Read, Execute.
  • r-x (Others) β€” Read, Execute.

Numeric Mode (Octal)

  • 4 = Read (r)
  • 2 = Write (w)
  • 1 = Execute (x)

Common Examples:

  • 777 (rwxrwxrwx) β€” Full access for everyone (Dangerous!).
  • 755 (rwxr-xr-x) β€” Owner can do everything, others can read/execute (Standard for scripts/directories).
  • 644 (rw-r--r--) β€” Owner can read/write, others can read (Standard for files).
  • 600 (rw-------) β€” Owner read/write only (Private keys/passwords).

Commands

  • chmod <mode> <file> β€” Change file mode bits.
    • chmod 755 script.sh
    • chmod +x script.sh (Add execute permission).
    • chmod u+w file.txt (Add write permission for user).
  • chown <user>:<group> <file> β€” Change file owner and group.
    • chown root:root /etc/file
    • chown -R user:user /var/www (Recursive).
  • chgrp <group> <file> β€” Change group ownership.

Special Permissions & Umask

  • umask β€” Sets default permissions for new files/directories (e.g., 022 results in 755 dirs and 644 files).
  • sudo β€” Run command as superuser (root).