ddn*_*mad 5 command-line encryption gpg
我想创建一个脚本,该脚本会自动加密并将一些我不想公开的敏感文件推送到 GitHub 并将其推送到公共存储库中(但确实想与整个项目保持在一起)。
作为解决方案,我决定用 GPG 加密它们。问题是我找不到任何关于如何使用作为 CLI 参数传递给gpg -c命令的密码短语加密特定文件的线索。
有人知道怎么做这个吗?
Ste*_*itt 10
Use one of the --passphrase-... options, in batch mode:
--passphrase-fd reads the passphrase from the given file descriptor
echo mysuperpassphrase | gpg --batch -c --passphrase-fd 0 file
Run Code Online (Sandbox Code Playgroud)
--passphrase-file reads the passphrase from the given file
echo mysuperpassphrase > passphrase
gpg --batch -c --passphrase-file passphrase file
Run Code Online (Sandbox Code Playgroud)
--passphrase uses the given string
gpg --batch -c --passphrase mysuperpassphrase file
Run Code Online (Sandbox Code Playgroud)
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.