Introduction
Understanding the Linux file system hierarchy and permission model is crucial for system administration and security. Every file and directory has an owner, a group, and a set of permissions that control access.
Directory Structure
/ # Root directory
/bin # Essential binaries
/etc # Configuration files
/home # User home directories
/var # Variable data (logs, cache)
/usr # User programs
/tmp # Temporary files
/opt # Optional software
File Permissions
Every file has three permission sets: owner, group, and others. Each set has read (r), write (w), and execute (x) permissions.
# View permissions
ls -la
# -rwxr-xr-- 1 user group 4096 Jun 12 file.txt
# Change permissions (numeric)
chmod 755 script.sh # rwxr-xr-x
chmod 644 config.txt # rw-r--r--
# Change permissions (symbolic)
chmod u+x script.sh # Add execute for owner
chmod g-w file.txt # Remove write for group
Ownership
# Change owner
chown user:group file.txt
# Change ownership recursively
chown -R www-data:www-data /var/www/
# Change group
chgrp developers project/
Special Permissions
# Setuid - run as file owner
chmod u+s /usr/bin/program
# Setgid - inherit group
chmod g+s /shared/dir
# Sticky bit - only owner can delete
chmod +t /tmp
Summary
Linux permissions control access to files and directories. Understanding rwx notation, numeric codes, and special permissions is essential for securing your system.
YouTip