使用公共 GPG 密钥进行批量加密

使用公共 GPG 密钥进行批量加密

我为我的 Clonezilla USB 记忆棒编写了一个小脚本,它使我能够快速备份所有内容,而无需输入任何选项,只需运行该脚本即可。

接下来,我想将我的公共 GPG 密钥存储在棒上,并为我的备份添加一些加密,如下所示:

find . -maxdepth 1 -type f -not -iname "*.gpg" | while read file ; do
    gpg --encrypt-using-key-file "/path/to/my/keyfile" "$file"
    rm "$file"
done

使用公共 GPG 密钥文件正确加密文件的方法是什么,确保它不会提示用户输入?我实际上该怎么做?

答案1

您的密钥环中必须有目标密钥。我不确定目标密钥是否必须有效;最好是这样。

您应该使用棒上的配置目录。在该目录为空的情况下,您可以导入密钥:

gpg --homedir /dir/on/stick --import /target/key.asc

此操作只需执行一次。从你的脚本中你可以这样做:

gpg --homedir /dir/on/stick --trust-model always --recipient 0x12345678 \
  --output /path/to/encrypted_file.gpg --encrypt /source/file

您也可以考虑为该文件创建签名。但这会使操作变得更加复杂。

相关内容