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
  • CyberPanel
  • Mounting /tmp on a Separate File

Mounting /tmp on a Separate File

Mounting /tmp on a Secure Loopback Device

Objective

This document outlines the steps to securely mount `/tmp` using a loopback device and bind it to `/var/tmp`, ensuring enhanced security by applying restrictions such as `noexec`, `nosuid`, and `nodev`.

1. Create the Mount Directory

mkdir -p /usr/images/

This command creates the directory `/usr/images/` if it doesn’t already exist.
This directory will store the loopback file that will be used as the `/tmp` partition.

2. Create a 3GB Loopback File

dd if=/dev/zero of=/usr/images/tmpfile.bin bs=1 count=0 seek=3G

`dd` creates a blank file (`tmpfile.bin`) in `/usr/images/`.
`bs=1 count=0` ensures the file is not written immediately but is instead allocated virtually.
`seek=3G` specifies the file size (3GB).

3. Format the File as an ext4 Filesystem

mkfs.ext4 /usr/images/tmpfile.bin

Converts `tmpfile.bin` into an ext4 filesystem, allowing it to be mounted like a normal disk.

4. Stop Services That Use /tmp

systemctl stop mysql || systemctl stop lscpd.service || systemctl stop lshttpd.service || systemctl stop lsws.service

These services may be using `/tmp`. Stopping them prevents issues during unmounting.

5. Unmount /tmp

umount /tmp
umount -l /tmp

`umount /tmp`: Unmounts `/tmp`.
`umount -l /tmp`: Uses force unmount to detach `/tmp` if it’s still in use.

6. Mount the New Loopback File as /tmp

mount -o loop,rw,nodev,nosuid,noexec /usr/images/tmpfile.bin /tmp

Mounts `tmpfile.bin` as `/tmp` with:
`loop`: Uses it as a loopback device.
`rw`: Read/write access.
`nodev`: Prevents the creation of device files.
`nosuid`: Blocks execution of binaries with the SUID bit set.
`noexec`: Prevents execution of scripts and binaries in `/tmp`.

7. Set Proper Permissions for /tmp

chmod 1777 /tmp

`chmod 1777`: Sets `/tmp` as world-writable (`777`) with the sticky bit (`1`), ensuring only the owner of a file can delete it.

8. Bind-Mount /tmp to /var/tmp

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

Ensures `/var/tmp` follows the same restrictions as `/tmp`.

9. Update /etc/fstab for Persistent Mounting

vim /etc/fstab

Opens `/etc/fstab` for editing to make changes permanent.
Add these lines at the end of the file:

/usr/images/tmpfile.bin   /tmp   ext4    loop,rw,noexec,nosuid,nodev    0 0
/tmp /var/tmp none rw,noexec,nosuid,nodev,bind 0 0

Ensures `/tmp` and `/var/tmp` are automatically mounted at boot with security restrictions.

10. Apply the New fstab Configuration

mount -a

Rereads `/etc/fstab` and mounts all file systems specified in it.

11. Restart Services

systemctl restart lscpd.service || systemctl restart mysql || systemctl restart lshttpd.service || systemctl restart lsws.service

Restarts all previously stopped services to ensure proper functionality.
The last command tries restarting `lsws`, and if that fails, it reloads the service instead.

Conclusion

Following these steps ensures that `/tmp` is securely mounted using a loopback device with necessary security restrictions (`noexec`, `nosuid`, `nodev`).
This protects the system from unauthorized execution of scripts and binaries within `/tmp`, improving overall security.

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