The Linux Filesystem & Permissions

Understand the Linux filesystem hierarchy and master user permissions (chmod, chown).

The Linux Filesystem & Permissions

Unlike Windows, which splits drives into C:\ and D:\, Linux uses a single, unified filesystem tree starting at the root (/). Everything is a file or a directory under this root.

The Hierarchy Standard

  • /etc: Configuration files for the entire system (like /etc/ssh/sshd_config).
  • /var: Variable data, such as system logs (/var/log) or web server files (/var/www).
  • /home: Personal directories for users (/home/alice).
  • /bin & /sbin: Essential command binaries (like ls or reboot).
  • /root: The personal home directory for the all-powerful root user.

Understanding Permissions

Linux permissions dictate exactly who can read, write, or execute a file.

If you run ls -l, you will see something like this: -rwxr-xr-- 1 alice developers 1024 Jan 1 script.sh

Let’s break down -rwxr-xr--:

  • Type (-): A hyphen means it’s a file. A d means it’s a directory.
  • User/Owner (rwx): alice can Read, Write, and eXecute this file.
  • Group (r-x): Anyone in the developers group can Read and eXecute, but cannot write/modify it.
  • Others (r--): Everyone else on the system can only Read it.

Changing Permissions (chmod & chown)

Changing Ownership (chown)

To give a file to a different user or group:

# Give file to user 'bob' and group 'admins'
sudo chown bob:admins script.sh

Changing Permissions (chmod)

Permissions are often represented by octal numbers:

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

You add them together to get the permission level. For example, rwx = 4+2+1 = 7.

# Give Owner rwx (7), Group rx (5), Others rx (5)
chmod 755 script.sh

# Give Owner rw (6), Group r (4), Others nothing (0)
chmod 640 secret_keys.txt

Verification

To verify your changes applied correctly:

# View the detailed permissions of a file
ls -la script.sh

# Check your current user identity and groups
id