how to secure tmp partation in linux
1. Create separte partation for tmp , if you don't have the space to create a fresh /tmp partition on existing drives, you can use the loopback capabilities of the Linux kernel by creating a loopback filesystem that will be mounted as /tmp and can use the same restrictive mount options.
To create a 1GB loopback filesystem, execute the following commands.
[root@Centos7 ~]# dd if=/dev/zero of=/dev/tmpDIR bs=1024 count=1000000
1000000+0 records in
1000000+0 records out
1024000000 bytes (1.0 GB) copied, 5.32903 seconds, 192 MB/s
2. Backup Current /tmp Directory: Now backup the current /tmp directory using the syntax below which will keep the same permissions for the files currently in /tmp.
[root@Centos7 ~]# cp -Rpf /tmp /tmpbak
3.Modify fstab: You should add a line to the end of the /etc/fstab file so the tmp partation so tmp is mounted when the server reboots.
/dev/mapper/centos-tmp /tmp xfs rw,noexec,nosuid,nodev 0 0
/tmp /var/tmp none rw,noexec,nosuid,nodev,bind 0 0
## Bind /var/tmp to /tmp
mount -o rw,noexec,nosuid,nodev,bind /tmp/ /var/tmp/
## Remount /tmp
mount -o remount,noexec,nosuid,nodev /tmp
## Remount /dev/shm
mount -o remount,noexec,nosuid,nodev /dev/shm
4. Modify /tmp Directory Permissions:
To create a 1GB loopback filesystem, execute the following commands.
[root@Centos7 ~]# dd if=/dev/zero of=/dev/tmpDIR bs=1024 count=1000000
1000000+0 records in
1000000+0 records out
1024000000 bytes (1.0 GB) copied, 5.32903 seconds, 192 MB/s
2. Backup Current /tmp Directory: Now backup the current /tmp directory using the syntax below which will keep the same permissions for the files currently in /tmp.
[root@Centos7 ~]# cp -Rpf /tmp /tmpbak
3.Modify fstab: You should add a line to the end of the /etc/fstab file so the tmp partation so tmp is mounted when the server reboots.
/dev/mapper/centos-tmp /tmp xfs rw,noexec,nosuid,nodev 0 0
/tmp /var/tmp none rw,noexec,nosuid,nodev,bind 0 0
## Bind /var/tmp to /tmp
mount -o rw,noexec,nosuid,nodev,bind /tmp/ /var/tmp/
## Remount /tmp
mount -o remount,noexec,nosuid,nodev /tmp
## Remount /dev/shm
mount -o remount,noexec,nosuid,nodev /dev/shm
4. Modify /tmp Directory Permissions:
Comments