Securing /tmp and shm partitions

Securing /tmp and /dev/shm is a nice practice.  Lots of programs and scripts have access in there. So you don’t want code, malicious or not to run in there, trying to get root permissions or snoop on you.

Temporary storage directories such as /tmp, /var/tmp and /dev/shm provide storage space for malicious executables.
Crackers and hackers store executables in /tmp. Malicious users can use temporary storage directories to execute unwanted program and crack your server.

First because I forget, let’s bind /var/tmp to /tmp in /etc/fstab

Now we deal with /tmp only.

Update 28/03/2015: That practice was for many unstable and criticized also by many. Unfortunately for them, I was vindicated when even OpenBSD in the upcoming version does the same for the very same reasons. Security.

Security improvements:

  • /var/tmp is now a symbolic link to /tmp, as a first step towards reducing the “fill it up” attack surface against the /var partition.


If it’s a separate partition we only need a

If it’s not, we will create an image for it. The example is for 4GB, tune it as you like.

Modify /tmp line as follows:

You should to the same for shm:


Edit your /etc/fstab:
# nano /etc/fstab

“none /dev/shm tmpfs defaults,rw 0 0” to
“none /dev/shm tmpfs defaults,nosuid,noexec,rw 0 0”

Remount /dev/shm:
# mount -o remount /dev/shm
It should be fine now.

0 (0)
Article Rating (No Votes)
Rate this article
There are no attachments for this article.
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Linux - How to get Memory information
Viewed 502 times since Fri, Jun 8, 2018
OEL 7 – How to disable IPv6 on Oracle Linux 7
Viewed 3391 times since Fri, Aug 3, 2018
Linux Screen
Viewed 748 times since Sat, Jun 2, 2018
How To Create a Linux Swap File
Viewed 603 times since Fri, Jun 8, 2018
RHEL: XFS basic operations
Viewed 1201 times since Sat, Jun 2, 2018
ZFS: Create a new zfs filesystem
Viewed 625 times since Sun, Jun 3, 2018
How to convert RAW image to VDI and otherwise
Viewed 1123 times since Wed, Oct 3, 2018
Jak ustawić LVM, jak robić snapshoty oraz automatycznie powiększać LV, czyli małe howto
Viewed 1297 times since Sun, May 20, 2018
3 Ways to Check Linux Kernel Version in Command Line
Viewed 662 times since Fri, Apr 19, 2019
Inxi – A Powerful Feature-Rich Commandline System Information Tool for Linux
Viewed 8385 times since Sat, Jun 2, 2018