LinuxXXIX · Linux Security HardeningMount options
Mount options for security - nodev, nosuid, noexec
What you'll learn
- Explain what nodev, nosuid, and noexec do
- Apply security mount options to /tmp, /dev/shm, /var
- Recognise when noexec breaks applications
- Audit mount options for the fleet
Prerequisites
Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09
Filesystem mount options defend against a class of attacks that exploit user-writable filesystems. This lesson covers the security-relevant options and where to apply them.
The three primary options
| Option | Effect |
|---|---|
nodev | Do not interpret device files on this filesystem |
nosuid | Ignore setuid and setgid bits |
noexec | Do not allow execution of binaries on this filesystem |
Combined, they prevent:
- A user creating a device file (
mknod /tmp/disk b 8 0) and reading raw disks. - A user uploading a setuid binary and getting a root shell.
- A user uploading an executable and running it.
Where to apply
User-writable filesystems benefit most:
# /etc/fstab
tmpfs /tmp tmpfs defaults,nodev,nosuid,noexec,size=1G 0 0
tmpfs /dev/shm tmpfs defaults,nodev,nosuid,noexec,size=1G 0 0
/dev/sda1 /var ext4 defaults,nodev 0 2
/tmp and /dev/shm are the highest-priority targets. They
are world-writable and frequently used by attackers.
/var can usually have nodev. nosuid and noexec may
break some applications.
When not to apply
noexec breaks:
- Compilers in
/tmp(rare in production). - Any application that uses
/tmpfor executable code.
nosuid breaks:
sudoif it relies on a setuid binary in/tmp(rare; sudo’s binary is in/usr/bin).- Applications that expect setuid binaries on the filesystem.
nodev is safe almost everywhere except /dev itself.
Verify
mount | grep -E '/tmp|/dev/shm'
findmnt /tmp /dev/shm
cat /proc/self/mountinfo | grep -E '/tmp|/dev/shm'
Each should show the security options applied.
Test before persisting
A wrong mount option can break the boot:
# Test with a temporary mount
sudo mount -o remount,nodev,nosuid /tmp
# Verify applications still work
If the test passes, edit /etc/fstab:
UUID=... /tmp ext4 defaults,nodev,nosuid,noexec 0 2
Other useful options
| Option | Effect |
|---|---|
nosymfollow | Do not follow symlinks (extra safety) |
nodev | Do not interpret device files |
noatime | Do not update access times (performance + privacy) |
nodiratime | Do not update directory access times |
Application compatibility
Common cases where noexec breaks things:
- Compiled languages: gcc, javac, etc. - usually not in /tmp.
- Container runtimes: container processes may run from /var/lib/docker.
- Web applications: PHP and other CGI processes may store cached bytecode in /tmp.
- Some installers: install scripts may extract and run from /tmp.
Audit before applying noexec:
# What runs from /tmp?
sudo lsof +D /tmp 2>/dev/null | grep -i exec
If applications use /tmp for execution, either move them
to /var/tmp (which is not noexec) or remove noexec.
Knowledge check
Knowledge check · 3 questions
Q1. Which mount option prevents execution of binaries on the filesystem?
Q2. /dev/shm should always have nodev, nosuid, and noexec.
Q3. Which of the following are valid security mount options? Select all that apply.
Passing score: 75%. Answers are checked in this browser.