First open fstab using nano, or your chosen editor:
nano -w /etc/fstab
Next append the following like to the fstab file you just opened:
none /tmp tmpfs nodev,nosuid,noexec 0 0
If you opened using nano you can now close using ctrl+x and then answering “y” to save.
To apply the changes we now need to simply remount:
mount -o remount /tmp
Its always a good idea to test it worked so run the following command:
df -h
Within the output you should see something like:
none 4.1G 0 4.1MG 3% /tmp
There is also a /var/tmp dir that needs to be secured.
So firstly make a backup (don’t skip this step, you need the files in a bit)
mv /var/tmp /var/tmpfiles
We can now make a link to map /tmp to /var/tmp
ln -s /tmp /var/tmp
Restore the files from the backup you made before
cp /var/tmpfiles/* /tmp/
Restore the files from the backup you made before, and make sure that the files in tmpfiles are now in tmp.
ls /var/tmpfiles
ls /var/tmp
If it looks ok, you can remove the tmpfiles directory.
Rm -rf /var/tmpfiles