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

change:
“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
Attachments
There are no attachments for this article.
Comments
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
ZPOOL: Add a mirror to a concat zpool
Viewed 4457 times since Sun, Jun 3, 2018
Szybkie sprawdzenie zewnętrznego adresu IP i hosta
Viewed 3923 times since Thu, May 24, 2018
Extending Linux LVM partitions - scripts
Viewed 7250 times since Sun, May 20, 2018
LVM: Create a new Volume Group
Viewed 2629 times since Sat, Jun 2, 2018
Testing TLS/SSL encryption
Viewed 14040 times since Thu, Jan 16, 2020
RHEL: Building a custom kernel on RHEL 6
Viewed 4930 times since Sat, Jun 2, 2018
linux unix aix banner /etc/issue
Viewed 2533 times since Fri, Aug 3, 2018
RHEL: Bonding network interfaces
Viewed 4473 times since Sat, Jun 2, 2018
OpenSSL: Find Out SSL Key Length – Linux Command Line
Viewed 8242 times since Mon, Feb 18, 2019
ubuntu How to reset lost root password on Ubuntu 16.04 Xenial Xerus Linux
Viewed 8949 times since Tue, Dec 8, 2020