When Centos is installed without a specified partition by default, the logical volume does not have an independent/tmp, which may cause security risks./dev/shm is also one of the risks.
# Dd A 1 GB file, file/. tmpfs
Ddif =/dev/zeroof =/. tmpfsbs = 1 Mcount = 1000
# Create a file system
Mke2fs-j/. tmpfs
####################
Mke2fs 1.41.12 (17-May-2010)
/. Tmpfsisnotablockspecialdevice.
Proceedanyway? (Y, n) y
Filesystemlabel =
OStype: Linux
Blocksize = 4096 (log = 2)
Fragmentsize = 4096 (log = 2)
Stride = 0 blocks, Stripewidth = 0 blocks
64000 inodes, 256000 blocks
12800 blocks (5.00%) reservedforthesuperuser
Firstdatablock = 0
Maximumfilesystemblocks = 264241152
8 blockgroups
32768 blockspergroup, 32768 fragmentspergroup
8000 inodespergroup
Superblockbackupsstoredonblocks:
32768,983 04, 163840,229 376
Writinginodetables: done
Creatingjournal (4096 blocks): done
Writingsuperblocksandfilesystemaccountinginformation: done
Thisfilesystemwillbeautomaticallycheckedevery32mountsor
180 days, whichevercomesfirst. Usetune2fs-cor-itooverride.
####################
# Copying files
Cp-av/tmp. old
# Mount the dd File
Mount-oloop, noexec, nosuid, rw/. tmpfs/tmp
# Assign the default/tmp permission
Chmod1777/tmp
# Move the copied file back
Mv-f/tmp. old/*/tmp/
# Deleting folders
Rm-rf/tmp. old
# Modify/etc/fstab to enable automatic mounting after it is restarted
/. Tmpfs/tmp ext3 loop, nosuid, noexec, rw 0 0
# Soft link/var/tmp to/tmp
Mv/var/tmp/var/tmp_bak
Ln-s/tmp/var/tmp
Cp-Rf/var/tmp_bak/*/var/tmp
Rm-rf/var/tmp_bak/
# Test
# Go To The/tmp and/dev/shm directories respectively, create executable files, and grant 777 Permissions
[Root @ localhost/tmp]
# Ls-lA/tmp/| grepx. sh
-Rwxrwxrwx1rootroot22Jul2515: 08x. sh
[Root @ localhost/tmp]
# Cat/tmp/x. sh
#! /Bin/bash
Echotest
[Root @ localhost/tmp]
#/Tmp/x. sh
-Bash:/tmp/x. sh: Permissiondenied
[Root @ localhost/dev/shm]
# Ls-lA | grep x. sh
-Rwxrwxrwx1rootroot22Jul2515: 08x. sh
[Root @ localhost/dev/shm]
# Cat x. sh
#! /Bin/bash
Echotest
[Root @ localhost/dev/shm]
#/Dev/shm/x. sh
-Bash:/dev/shm/x. sh: Permissiondenied