使用作为 CLI 参数传递的密钥使用 GPG 进行加密

ddn*_*mad 5 command-line encryption gpg

我想创建一个脚本,该脚本会自动加密并将一些我不想公开的敏感文件推送到 GitHub 并将其推送到公共存储库中(但确实想与整个项目保持在一起)。

作为解决方案,我决定用 GPG 加密它们。问题是我找不到任何关于如何使用作为 CLI 参数传递给gpg -c命令的密码短语加密特定文件的线索。

有人知道怎么做这个吗?

Ste*_*itt 10

Use one of the --passphrase-... options, in batch mode:

These will all encrypt file (into file.gpg) using mysuperpassphrase.

With GPG 2.1 or later, you also need to set the PIN entry mode to “loopback”:

gpg --batch -c --pinentry-mode loopback --passphrase-file passphrase file
Run Code Online (Sandbox Code Playgroud)

etc.

Decryption can be performed in a similar fashion, using -d instead of -c, and redirecting the output:

gpg --batch -d --passphrase-file passphrase file.gpg > file
Run Code Online (Sandbox Code Playgroud)

etc.