[内容] Linux 目录的重新挂载

内容一:查看已挂载目录的状况

1.1 查看所有已挂载目录的状态

# mount

1.2 查看某个目录的挂载状态

# mount | grep /tmp

(补充:这里以查看 /tmp 目录的挂载状态为例)

内容二:重新挂载目录

1.1 手动重新挂载目录

# mount -o remount,nosuid,nodev,noexec /dev/shm


补充:
1) 这里以带 nosuid、nodev 和 noexec 参数重新挂载 /dev/shm 目录为例
2) 如果挂载的目录已经有了 nosuid、nodev 和 noexec 参数,但是想要取消这些参数,则在这里可以使用 suid、dev 和 exec 参数

1.2 开机自动重新挂载目录

# vim /etc/fstab

添加以下内容:

......
tmpfs /dev/shm tmpfs defaults,nosuid,nodev,noexec 0 0


补充:
1) 这里以带 nosuid、nodev 和 noexec 参数重新挂载 /dev/shm 目录为例
2) 如果挂载的目录已经有了 nosuid、nodev 和 noexec 参数,但是想要取消这些参数,则在这里可以使用 suid、dev 和 exec 参数

[步骤] Linux 软硬链接保护的开启 (防止通过软硬链接执行无权限执行的文件)

步骤一:开启软硬链接保护

1.1 修改 /etc/sysctl.conf 文件

# vim /etc/sysctl.conf

添加以下内容:

......
fs.protected_hardlinks = 1
fs.protected_symlinks = 1

1.2 设置系统正在运行的 fs.protected_symlinks 参数和 fs.protected_hardlinks 参数

# sysctl -w fs.protected_symlinks = 1
# sysctl -w fs.protected_hardlinks = 1

步骤二:显示软硬链接保护的开启状态

2.1 显示 /etc/sysctl.conf 文件里的 fs.protected_symlinks 参数和 fs.protected_hardlinks 参数

# grep "fs\.protected_hardlinks" /etc/sysctl.conf /etc/sysctl.d/*
fs.protected_hardlinks = 1
# grep "fs\.protected_symlinks" /etc/sysctl.conf /etc/sysctl.d/*
fs.protected_symlinks = 1

2.2 显示系统正在运行的 fs.protected_symlinks 参数和 fs.protected_hardlinks 参数

# sysctl fs.protected_symlinks
fs.protected_symlinks = 1
# sysctl fs.protected_hardlinks
fs.protected_hardlinks = 1

[步骤] Linux 加密压缩 (tar 版)

步骤一:创建测试文件

# touch test.txt

(补充:这里以创建 test.txt 文件为例)

步骤二:加密压缩文件或目录

2.1 交互式加密压缩文件或目录

# tar -zcf - test.txt | openssl des3 -salt | dd of=test1.tar.gz
enter des-ede3-cbc encryption password:
Verifying - enter des-ede3-cbc encryption password:
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.
0+1 records in
0+1 records out
224 bytes copied, 7.04902 s, 0.0 kB/s


补充:
1) 这里以将 test.txt 文件加密压缩成 test1.tar.gz (压缩)包为例
2) 如果要以 bzip2 的格式进行压缩,则将命令中的 -zcf 换成 -jcvf 将 test1.tar.gz 换成 test1.tar.bz2
3) 如果要以 xz 的格式进行压缩,则将命令中的 -zcf 换成 -Jcvf 将 test1.tar.gz 换成 test1.tar.xz

2.2 非交互式加密压缩文件或目录

# tar -zcf - test.txt | openssl des3 -salt -f eternalcenter | dd of=test2.tar.gz
des3: Unrecognized flag f
des3: Use -help for summary.
0+0 records in
0+0 records out
0 bytes copied, 0.00376576 s, 0.0 kB/s


补充:
1) 这里以将 test.txt 文件加密压缩成 test1.tar.gz (压缩)包并且将密码设置为 eternalcenter 为例
2) 如果要以 bzip2 的格式进行压缩,则将命令中的 -zcf 换成 -jcvf 将 test1.tar.gz 换成 test2.tar.bz2
3) 如果要以 xz 的格式进行压缩,则将命令中的 -zcf 换成 -Jcvf 将 test1.tar.gz 换成 test2.tar.xz

步骤三:解压加密文件或目录

3.1 交互式解压加密文件或目录

3.1.1 删除原测试目录和里面的文件
# rm -rf test.txt

(补充:这里以删除 test.txt 文件为例)

3.1.2 交互式解压加密文件或目录
# dd if=test2.tar.gz | openssl des3 -d | tar zxf -
0+1 records in
0+1 records out
224 bytes copied, 0.000589721 s, 380 kB/s
enter des-ede3-cbc decryption password:
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.


补充:
1) 这里以解压 test2.tar.gz (压缩)包为例
2) 如果是 bzip2 格式的(压缩)包,则将命令中的 -zxf 换成 -jcvf 将 test1.tar.gz 换成 test1.tar.bz2
3) 如果是 xz 格式的(压缩)包,则将命令中的 -zxf 换成 -Jcvf 将 test1.tar.gz 换成 test1.tar.xz

3.2 非交互式解压加密文件或目录

3.2.1 删除原测试目录和里面的文件
# rm -rf test.txt

(补充:这里以删除 test.txt 文件为例)

3.2.2 非交互式解压加密文件或目录
# dd if=test1.tar.gz | openssl des3 -d -k eternalcenter | tar zxf -
0+1 records in
0+1 records out
224 bytes copied, 0.000574539 s, 390 kB/s
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.


补充:
1) 这里以解压 test1.tar.gz (压缩)包并且解压密码为 eternalcenter 为例
2) 如果是 bzip2 格式的(压缩)包,则将命令中的 -zxf 换成 -jcvf 将 test1.tar.gz 换成 test1.tar.bz2
3) 如果是 xz 格式的(压缩)包,则将命令中的 -zxf 换成 -Jcvf 将 test1.tar.gz 换成 test1.tar.xz

[步骤] Linux 加密压缩 (zip 版)

步骤一:创建测试目录和测试文件

# mkdir test
# touch test/test.txt

(补充:这里以创建 test 目录和里面的 test.txt 文件为例)

步骤二:加密压缩文件或目录

2.1 交互式加密压缩文件或目录

# zip -re test1.zip test
Enter password: 
Verify password: 
  adding: test/ (stored 0%)
  adding: test/test.txt (stored 0%)

(补充:这里以将 test 目录和里面的 test.txt 文件加密压缩成 test1.zip (压缩)包为例)

2.2 非交互式加密解压文件或目录

# zip -rP eternalcenter test2.zip test
  adding: test/ (stored 0%)
  adding: test/test.txt (stored 0%)

(补充:这里以将 test 目录和里面的 test.txt 文件加密压缩成 test2.zip (压缩)包并且将密码设置为 eternalcenter 为例)

步骤三:解压加密文件或目录

3.1 交互式解压加密文件或目录

3.1.1 删除原测试目录和里面的文件
# rm -rf test

(补充:这里以删除 test 目录和里面的文件为例)

3.1.2 交互式解压加密文件或目录
# unzip test2.zip
Archive:  test2.zip
   creating: test/
[test2.zip] test/test.txt password: 
 extracting: test/test.txt

(补充:这里以解压 test2.zip (压缩)包为例)

3.2 非交互式解压加密文件或目录

3.2.1 删除原测试目录和里面的文件
# rm -rf test

(补充:这里以删除 test 目录和里面的文件为例)

3.2.2 非交互式解压加密文件
# unzip -P eternalcenter test1.zip 
Archive:  test1.zip
   creating: test/
 extracting: test/test.txt  

(补充:这里以解压 test2.zip (压缩)包并且解压密码为 eternalcenter 为例)