面试题答案
一键面试- 密钥管理:
- 确保
secure_group
组内成员的公钥已收集并导入到本地密钥环。假设公钥文件为member1.pub
,member2.pub
等,可以使用以下命令导入公钥:
gpg --import member1.pub gpg --import member2.pub
- 确保
- 文件加密Bash脚本编写:
- 创建一个名为
encrypt_file.sh
的脚本:
#!/bin/bash if [ $# -ne 2 ]; then echo "Usage: $0 <input_file> <output_encrypted_file>" exit 1 fi input_file=$1 output_file=$2 gpg --recipient secure_group --output $output_file --encrypt $input_file
- 给脚本添加执行权限:
chmod +x encrypt_file.sh
- 创建一个名为
- 文件解密Bash脚本编写:
- 创建一个名为
decrypt_file.sh
的脚本:
#!/bin/bash if [ $# -ne 2 ]; then echo "Usage: $0 <input_encrypted_file> <output_decrypted_file>" exit 1 fi input_file=$1 output_file=$2 gpg --output $output_file --decrypt $input_file
- 给脚本添加执行权限:
chmod +x decrypt_file.sh
- 创建一个名为
- 设置权限确保安全性:
- 对于加密后的文件,确保只有
secure_group
组内成员有读取权限:
chgrp secure_group encrypted_file.gpg chmod g+r encrypted_file.gpg chmod o-r encrypted_file.gpg
- 对于私钥,确保只有所有者有读取和写入权限:
chmod 600 ~/.gnupg/private -r
- 对于
encrypt_file.sh
和decrypt_file.sh
脚本,确保只有所有者有执行权限:
chmod 700 encrypt_file.sh chmod 700 decrypt_file.sh
- 对于加密后的文件,确保只有