Skip to content
  • About
  • Contact
  • Docs
  • Features
  • Home

Configurations

5
  • Setup RAID Level 6
  • Setup RAID Level 5
  • How To Add Swap on RHEL or Centos based system
  • Website Migration to Non-Panel OpenLiteSpeed Server
  • Linux Server Performance Tuning

CyberPanel

9
  • Mounting /tmp on a Separate File
  • Updating CyberPanel Main VirtualHost Configuration
  • Updating CyberPanel vHosts Configuration
  • How to Change CLI PHP on CyberPanel
  • How to Update PHP Version to 8.1 in CyberPanel (From 7.3, 7.4, or 8.0)
  • CyberPanel Server Cleanup: Logs, Dumps, Backups
  • CyberPanel Full LSPHP Installation PHP 7.4 โ€“ 8.3
  • CyberPanel / OpenLiteSpeed: Clean LSPHP Session Files
  • SSL Certificate Management in CyberPanel via SSH

Hestia Control Panel

6
  • Fixing Email Bounce Back Issue in Hestia (Exim4 Blacklist Rejection)
  • Managing Fail2Ban in HestiaCP Server
  • Installing and Configuring PHP Versions in HestiaCP
  • phpMyAdmin Not Found in HestiaCP
  • Setting Up a Reverse Proxy for any Port in HestiaCP
  • How to Install Let’s Encrypt SSL in Hestia CP (Hostname, Admin Panel, and Email Server)

WHM/cPanel

6
  • Setting Up a Reverse Proxy on cPanel/WHM for Port 8081
  • How to increase the size of the cPanel-generated /tmp filesystem
  • Installing Old PHP Versions on a cPanel/WHM Server
  • Fixing “550: Your Country is Not Allowed to Connect to This Server” Error in Exim (cPanel)
  • Enable WP-CLI in CageFS on CloudLinux Servers (WHM/cPanel)
  • Securing /tmp and /var/tmp with a Dedicated Loopback Filesystem

Nagios

5
  • Service Checks
  • Uptime Checks
  • Disk Space Checks
  • Load Checks
  • Email Related Checks

WordPress

3
  • WordPress Core Reinstallation Guide
  • Managing WordPress Users via WP-CLI
  • Website Duplication, Migration, or Domain Change

Operating System

1
  • Server Reboot (RHEL or Centos based system)

AWS

1
  • How to Resize EBS Volumes on AWS

Databases

2
  • MySQL
    • Optimizing MySQL Performance
    • Recovering MySQL in Plesk When InnoDB Crashes

CloudLinux

4
  • Moving cagefs-skeleton directory
  • Enable WP-CLI in CageFS on CloudLinux Servers (WHM/cPanel)
  • Enable bc in CageFS on CloudLinux Servers(WHM/cPanel)
  • How to Upgrade MySQL 5.x to MySQL 8.0 on CloudLinux (WHM server) with MySQL Governor

Cloudflare

1
  • Configuring Security Headers in Cloudflare

ISPmanager

1
  • Install Free SSL (Let’s Encrypt) for domain.tld on ISPmanager with NGINX

Plesk

1
  • Plesk Admin Login Blocked โ€“ IP Restriction Recovery Guide

VPN

4
  • Install OpenVPN Open Source in Linux CentOS Ubuntu Debian Servers
  • Protected: OpenVPN Installation & Fix Wiki (CloudLinux / CentOS 7 & 8)
  • Outline VPN Installation & Management Guide
  • Installing AdGuard Home on Debian/Ubuntu (Docker)
View Categories
  • Home
  • Docs
  • WHM/cPanel
  • Securing /tmp and /var/tmp with a Dedicated Loopback Filesystem

Securing /tmp and /var/tmp with a Dedicated Loopback Filesystem

๐Ÿ”’ Securing `/tmp` and `/var/tmp` with a Dedicated Loopback Filesystem

๐Ÿ“Œ Purpose

๐Ÿšซ Prevent malicious code execution โ€“ Stops attackers from running scripts in `/tmp`.
๐Ÿ” Block setuid exploits โ€“ `nosuid` prevents privilege escalation.
๐Ÿ›ก Isolate `/tmp` from root โ€“ Limits filesystem exposure if `/tmp` is compromised.
๐Ÿ”„ Apply same restrictions to `/var/tmp`** โ€“ Ensures uniform security for temporary directories.

 

๐Ÿ›  Step-by-Step Guide

Unmount Existing `/tmp` and `/var/tmp`

umount /tmp

umount -l /tmp

umount -l /var/tmp

ย umount โ†’ detaches a filesystem.
-l โ†’ lazy unmount, detaches immediately but cleans up references later.
Ensures /tmp and /var/tmp can be reconfigured safely.

Stop Services Using `/tmp`
systemctl stop mysql || systemctl stop httpd

systemctl stop mysqld.service

Stops services that might be using `/tmp`.
|| โ†’ attempts the next command if the first fails.
Prevents files from being locked while remounting `/tmp`.

Backup Old Disk File
mv /usr/tmpDSK /usr/tmpDSK_bk

Moves the old disk file to a backup location.
Preserves data in case rollback is needed.

Create a New Disk File (4GB)
dd if=/dev/zero of=/usr/tmpDSK bs=1 count=0 seek=4G

dd โ†’ low-level file creation.
if=/dev/zero โ†’ fills with zeros.
seek=4G โ†’ reserves 4GB sparse file for /tmp.

Format as ext4
mkfs.ext4 /usr/tmpDSK

Formats the file as an ext4 filesystem.
Required to mount as a loopback device.

Mount the Disk as `/tmp`
mount -o loop,rw,nodev,nosuid,noexec /usr/tmpDSK /tmp
chmod 1777 /tmp

`loop` โ†’ treat the file as a block device.
`rw` โ†’ read/write.
`nodev` โ†’ block device files disabled.
`nosuid` โ†’ ignore setuid bits.
`noexec` โ†’ prevent executing binaries.
`chmod 1777` โ†’ world-writable with sticky bit (users only delete own files).

Bind-Mount `/var/tmp`
mount -o rw,noexec,nosuid,nodev,bind /tmp /var/tmp

Shares `/tmp` restrictions with `/var/tmp`.
Prevents setuid, device files, and executable scripts.

Verify Mounts
df -Th

Shows all mounted filesystems and types.
Confirms `/tmp` and `/var/tmp` are mounted correctly.

Make Mounts Persistent
vim /etc/fstab

Add:

/usr/tmpDSK /tmp ext4 defaults,noauto,loop,rw,nodev,nosuid,noexec 0 0
mount -a

`/etc/fstab` โ†’ persistent mount configuration.
`mount -a` โ†’ mounts all filesystems listed in fstab.

Restart Services
systemctl start httpd
systemctl start mysqld.service

Restart web, database, and spam services.
Ensures normal operations resume after remounting `/tmp`.

โœ… Verification

cd /tmp
touch test.txt
ls -l

Tests that `/tmp` is writable.
Confirms permissions and proper mount.

๐Ÿ›ก Security Benefits

๐Ÿ“ฆ `/tmp` is isolated from root filesystem.
๐Ÿ” Prevents execution of untrusted scripts.
๐Ÿ”„ `/var/tmp` inherits the same restrictions.
๐Ÿš€ Reduces attack surface and improves security.

๐Ÿ†˜ Troubleshooting

Service fails to start:** Check `/tmp` permissions (`chmod 1777 /tmp`).
Disk full:** Resize `/usr/tmpDSK` with `dd` and `resize2fs`.
Changes not persistent:** Verify `/etc/fstab` entry and run `mount -a`.

Table of Contents
  • ๐Ÿ›  Step-by-Step Guide
    • Stop Services Using `/tmp`
    • Backup Old Disk File
    • Create a New Disk File (4GB)
    • Format as ext4
    • Mount the Disk as `/tmp`
    • Bind-Mount `/var/tmp`
    • Verify Mounts
    • Make Mounts Persistent
    • Restart Services
    • ๐Ÿ›ก Security Benefits
    • ๐Ÿ†˜ Troubleshooting

Share This Article :

  • Facebook
  • X
  • LinkedIn
  • Pinterest

Was it helpful ?

  • Happy
  • Normal
  • Sad
  • About
  • Contact
  • Docs
  • Features
  • Home

© 2026 Panel Web Hosting

  • About
  • Contact
  • Docs
  • Features
  • Home