Explain Linux file permissions and how to change them.

Beginner

Answer

Linux uses a three-tier permission system:

  • Owner (u): The file owner
  • Group (g): The file's group
  • Others (o): All other users
    Each tier has three permissions:
  • Read (r): Permission to read the file (4)
  • Write (w): Permission to modify the file (2)
  • Execute (x): Permission to execute the file (1)
    Example: rwxr-xr-- means owner has read/write/execute, group has read/execute, others have read only.
# Change permissions using chmod
chmod 755 file.txt        # rwxr-xr-x
chmod u+x script.sh       # Add execute for owner
chmod g-w file.txt        # Remove write for group
chmod o=r file.txt        # Set others to read only
# Change ownership
chown user:group file.txt
chgrp newgroup file.txt