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
“Too many authentication failures” with SSH
Viewed 7132 times since Mon, May 21, 2018
10 Linux DIG Command Examples for DNS Lookup
Viewed 11983 times since Sun, Sep 30, 2018
How to encrypt a partition with DM-Crypt LUKS on Linux
Viewed 9064 times since Fri, Jul 13, 2018
Linux File Systems (mkfs, mount, fstab) ext4
Viewed 4036 times since Sat, Jun 2, 2018
Installing and Configuring an OCFS2 Clustered File System
Viewed 6902 times since Sat, Jun 2, 2018
stunnel How To Set Up an SSL Tunnel Using Stunnel on Ubuntu
Viewed 2668 times since Sun, Dec 6, 2020
How to enable Proxy Settings for Yum Command on RHEL / CentOS Servers
Viewed 14263 times since Thu, Jul 19, 2018
Transform XML to CSV Format | Unix String Pattern Manipulation The Ugly Way
Viewed 8044 times since Sun, Jan 9, 2022
Learn how to align an SSD on Linux
Viewed 14167 times since Fri, May 15, 2020
How to stop and disable auditd on RHEL 7
Viewed 42574 times since Tue, Aug 6, 2019