How to mount /tmp as a separate filesystem with the noexec,nosuid options

How to mount /tmp as a separate filesystem with the noexec,nosuid options

There are many reasons you might need to mount your /tmp dir as a separate filesystem. Not doing this is a major security flaw and could potentially allow remote executables to run on your system without your permission. I have installed CSF+LFD on a brand new CentOS 5.6 system and when running the security check, CSF+LFD looks for this. Therefore, this is normally one of the first steps I take when securing the system. Here are the steps you should take…

  1. Backup your fstab
  2. cp /etc/fstab /etc/fstab.bak

  3. Create 1GB tmpmnt partition file
  4. cd /var
    dd if=/dev/zero of=tmpMnt bs=1024 count=1048576

  5. Format new partition
  6. mkfs.ext3 -j /var/tmpMnt
    Press Y when asked

  7. Backup old /tmp
  8. cp -Rp /tmp /tmp_backup

  9. Mount the new /tmp filesystem
  10. mount -o loop,noexec,nosuid,rw /var/tmpMnt /tmp

  11. Set the appropriate permissions
  12. chmod 1777 /tmp

  13. Copy files back to /tmp
  14. cp -Rp /tmp_backup/* /tmp/

  15. Add new /tmp to fstab
  16. echo “/var/tmpMnt /tmp ext3 loop,rw,noexec,nosuid,nodev 0 0″ >> /etc/fstab

  17. Symlink /var/tmp to /tmp
  18. rm -rf /var/tmp/
    ln -s /tmp/ /var/tmp

About the Author

Brad Laszlo is a Systems Engineer for Prestige Technologies, reigning from Michigan. Brad is specialized in server configuration and manipulation using both Microsoft and Linux technologies, and considers himself to be a novice tech writer (and Bio writer). Brad can be reached at bradlaszlo[at]prestigetech[dot]com or by visiting http://www.prestigetech.com