Temporary storage directories such as /tmp, /var/tmp and /dev/shm provide storage space for malicious executables.
| Tutorial details | |
|---|---|
| Difficulty | Intermediate (rss) |
| Root privileges | Yes |
| Requirements | Linux |
| Estimated completion time | N/A |
Add nodev, nosuid, and noexec options to /tmp
Edit the file /etc/fstab, enter:
# vi /etc/fstab
Locate the /tmp line:
UUID=0aef28b9-3d11-4ab4-a0d4-d53d7b4d3aa4 /tmp ext4 defaults 1 2
Append the text ,nodev,nosuid,noexec to the list of mount options in column 4. In the end, your entry should look like as follows:
UUID=0aef28b9-3d11-4ab4-a0d4-d53d7b4d3aa4 /tmp ext4 defaults,nodev,nosuid,noexec 1 2Save and close the file.
Add nodev, nosuid, and noexec options to /dev/shm
Edit the file /etc/fstab, enter:
# vi /etc/fstab
Locate the /dev/shm line:
tmpfs /dev/shm tmpfs defaults 0 0
Append the text ,nodev,nosuid,noexec to the list of mount options in column 4. In the end, your entry should look like as follows:
tmpfs /dev/shm tmpfs defaults,nodev,nosuid,noexec 0 0Save and close the file.
A note about /var/tmp
Make sure you bind /var/tmp to /tmp. Edit the file /etc/fstab, enter:
# vi /etc/fstab
Append the following line:
/tmp /var/tmp none rw,noexec,nosuid,nodev,bind 0 0
Save and close the file.
Set nodev, nosuid, and noexec options without rebooting the Linux server
Type the following command as root user:
## Bind /var/tmp to /tmp mount -o rw,noexec,nosuid,nodev,bind /tmp/ /var/tmp/ ## Remount /tmp mount -o remount,noexec,nosuid,nodev /tmp ## Remount /dev/shm mount -o remount,noexec,nosuid,nodev /dev/shm
Verify new settings:
# mount
# mount | less
# mount | egrep --color -w '^(tmpfs|/tmp)|/tmp'
Sample outputs:
How do I mount /tmp as a filesystem?
You can mount $jail/tmp as a separate filesystem using a file called /images/tmpfile.bin with the noexec,nosuid, nodev options under Linux like operating systems.
See also
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 5 comments… read them below or add one }
…and afterwards aptitude isn’t working anymore! :P
If this is the case – and it will be! – edit your ‘/etc/apt/apt.conf’ and add the following lines:
Kind regards.
Debian (apt-get respectively) has some troubles when /tmp is mounted with ‘noexec’. Please check http://www.debian-administration.org/articles/57 for a work-around.
Hi,
Normally some applications generates script dynamically
under /tmp and execute it…
Thanks….
hi , thanks, it was good.
To mount /tmp and /var/tmp from within a VPS
mount -t tmpfs -o noexec,nosuid,nodev tmpfs /tmp
mount -t tmpfs -o noexec,nosuid,nodev tmpfs /var/tmp
To check the mounted ‘tmp’ partitions, execute
mount | grep tmp