Secure Tmp Directadmin / Plesk

Here are few simple steps to create/secure /tmp partition on the server installed with Directadmin or plesk panel.

 

1 -> SSH the server as root.

 

2 -> Create the /tmp/tmpMnt using dd (the below example with create a 2.4 GB partition)

 

  • # dd if=/dev/zero of=/dev/tmpMnt bs=1024 count=2500000

 

3 -> Make an extended filesystem (ext3) over /dev/tmpMnt

 

  • # /sbin/mkfs -t ext3 /dev/tmpMnt

 

4 -> Backup the existing /tmp partiton

 

  • # cp -R /tmp /tmp_backup

 

5 -> Mount the new /tmp filesystem with noexec

 

  • # mount -o loop,noexec,nosuid,rw /dev/tmpMnt /tmp

 

6 -> Copy everything back to new /tmp and remove backup

 

  • # cp -R /tmp_backup/* /tmp/ ; rm -rf /tmp_backup

 

7 -> Edit the /etc/fstab and add the following line at the bottom (Save & exit)

 

  • # /dev/tmpMnt    /tmp     ext3    loop,noexec,nosuid,rw   0 0

 

8 -> Test it using the mount and umount commands

 

  • # umount /tmp
    # mount /tmp

 

9 -> List the partition and make sure it is added correctly

 

  • # df -h
    # mount

 

The output may look similar below.

 

Tmp Partition