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
logrotate Log Rotate Configuration
Viewed 3909 times since Sun, Jan 12, 2020
RHCS6: Show/Add GFS2/GFS journals
Viewed 13408 times since Sun, Jun 3, 2018
SSH Essentials: Working with SSH Servers, Clients, and Keys
Viewed 5574 times since Wed, Jun 27, 2018
How to Register and Enable Red Hat Subscription, Repositories and Updates for RHEL 7.0 Server
Viewed 15192 times since Mon, Oct 29, 2018
RHEL7: Create and configure LUKS-encrypted partitions and logical volumes to prompt for password and mount a decrypted file system at boot.
Viewed 14344 times since Mon, Aug 6, 2018
Linux / UNIX: Run Command a Number of Times In a Row
Viewed 16565 times since Tue, Aug 6, 2019
Fałszujemy rozpoznania skanerów #2
Viewed 3602 times since Mon, May 21, 2018
Linux - How to get IP and MAC address of ethernet adapter in Linux
Viewed 3404 times since Fri, Jun 8, 2018
RHEL: Extending the maximum inode count on a ext2/ext3/ext4 filesystem
Viewed 4344 times since Sun, May 27, 2018
How to remove CTRL-M (^M) characters from a file in Linux
Viewed 3463 times since Thu, Feb 7, 2019