Course contentsShow
← Security
Lesson 1411 of 3,05229. Operating System Security - HardeningFree lesson

Filesystem Hardening and Mount Options

Using mount options like noexec, nosuid, and nodev to restrict malicious activity on filesystem partitions.

Filesystem Hardening and Mount Options

What you'll learn: How to use filesystem mount options to prevent attackers from exploiting directories with malicious executables, setuid binaries, or device files.

The Core Idea

When you mount a filesystem partition in Linux or Unix, you can apply special restrictions that limit what can be done on that filesystem—even by privileged users. Three critical mount options help prevent common privilege escalation and code execution attacks:

  • noexec: Prevents execution of binaries on this partition
  • nosuid: Ignores setuid/setgid bits (prevents privilege escalation via setuid programs)
  • nodev: Prevents interpretation of device files

Think of these like hotel room rules: "No cooking in the room" (noexec), "No pets allowed" (nosuid), and "Don't tamper with fire alarms" (nodev). Even if someone brings prohibited items, the rules prevent their use.

Why This Matters

Attackers often upload malicious executables to world-writable directories like /tmp or /var/tmp, then execute them. If /tmp is mounted with noexec,nosuid,nodev, uploaded malware simply won't run—even if the attacker has write access.

Common hardened mount configurations:

/tmp          ext4    defaults,noexec,nosuid,nodev    0 0
/var/tmp      ext4    defaults,noexec,nosuid,nodev    0 0
/home         ext4    defaults,nodev                  0 0
/dev/shm      tmpfs   defaults,noexec,nosuid,nodev    0 0

You typically add these in /etc/fstab, then remount or reboot.

Defense in Depth

This approach complements (but doesn't replace) other hardening measures you've learned: disabling services, removing packages, and network hardening. It creates an additional barrier specifically targeting filesystem-based attacks.

Key Takeaway: Mount options like noexec, nosuid, and nodev restrict dangerous operations on specific partitions, blocking common attack vectors even when other defenses fail.