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
List of 10 Must Know Oracle Database Parameters for Database Administrator
Viewed 129997 times since Thu, Jun 21, 2018
Inxi – A Powerful Feature-Rich Commandline System Information Tool for Linux
Viewed 18977 times since Sat, Jun 2, 2018
Linux - How to monitor CPU usage
Viewed 6536 times since Fri, Jun 8, 2018
Linux - How to get Memory information
Viewed 1995 times since Fri, Jun 8, 2018
RHEL: Rebuilding the initial ramdisk image
Viewed 7676 times since Sat, Jun 2, 2018
Applescript: Run or Call a Shell Script
Viewed 4299 times since Tue, Aug 6, 2019
SPRAWDZONA KONFIGURACJA RSYSLOG I LOGROTATE, JAKO ZEWNĘTRZNEGO SERWERA SYSLOG
Viewed 3897 times since Fri, Nov 30, 2018
ZFS: Verify/change properties of a zfs filesystem
Viewed 2683 times since Sun, Jun 3, 2018
Jak wygenerować silne hasła jednorazowe w Linuksie?
Viewed 2409 times since Thu, May 24, 2018
Linux - Cannot login from remote console but can access via ssh
Viewed 5304 times since Fri, Jun 8, 2018