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
Linux LVM recovery
Viewed 17627 times since Wed, Jan 23, 2019
18 Quick ‘lsof’ command examples for Linux Geeks
Viewed 11440 times since Sun, Jun 30, 2019
Logrotate Example for Custom Logs
Viewed 2501 times since Sun, Jan 12, 2020
Installing and Configuring stunnel on CentOS 6
Viewed 4004 times since Fri, Sep 28, 2018
LVM: Extend SWAP size by adding a new Logical Volume
Viewed 3071 times since Sat, Jun 2, 2018
Top 4 Reasons for Node Reboot or Node Eviction in Real Application Cluster (RAC) Environment
Viewed 90011 times since Thu, Jun 21, 2018
Increase A VMware Disk Size (VMDK) Formatted As Linux LVM without rebooting
Viewed 15279 times since Wed, May 30, 2018
Easily Find Bugs In Shell Scripts With ShellCheck
Viewed 3233 times since Thu, Apr 18, 2019
CentOS / RHEL 7 : Configuring an NFS server and NFS client Linux NFS
Viewed 16287 times since Fri, Feb 21, 2020
Linux: how to monitor the nofile limit
Viewed 10535 times since Wed, Jul 25, 2018