{"id":89938,"date":"2024-02-29T06:04:13","date_gmt":"2024-02-28T22:04:13","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=89938"},"modified":"2024-02-29T06:04:13","modified_gmt":"2024-02-28T22:04:13","slug":"gpg-encrypt-decrypt","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/gpg-encrypt-decrypt.html","title":{"rendered":"\u4f7f\u7528 GPG \u52a0\u5bc6\u548c\u89e3\u5bc6\u6587\u4ef6"},"content":{"rendered":"
\u76ee\u6807\uff1a\u4f7f\u7528 GPG \u52a0\u5bc6\u6587\u4ef6<\/p>\n
\u53d1\u884c\u7248\uff1a\u9002\u7528\u4e8e\u4efb\u4f55\u53d1\u884c\u7248<\/p>\n
\u8981\u6c42\uff1a\u5b89\u88c5\u4e86 GPG \u7684 Linux \u6216\u8005\u62e5\u6709 root \u6743\u9650\u6765\u5b89\u88c5\u5b83\u3002<\/p>\n
\u96be\u5ea6\uff1a\u7b80\u5355<\/p>\n
\u7ea6\u5b9a\uff1a<\/p>\n
\u52a0\u5bc6\u975e\u5e38\u91cd\u8981\u3002\u5b83\u5bf9\u4e8e\u4fdd\u62a4\u654f\u611f\u4fe1\u606f\u6765\u8bf4\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002\u4f60\u7684\u79c1\u4eba\u6587\u4ef6\u5e94\u8be5\u8981\u88ab\u52a0\u5bc6\uff0c\u800c GPG \u63d0\u4f9b\u4e86\u5f88\u597d\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n
GPG \u7684\u4f7f\u7528\u975e\u5e38\u5e7f\u6cdb\u3002\u4f60\u5728\u51e0\u4e4e\u6bcf\u4e2a\u53d1\u884c\u7248\u7684\u4ed3\u5e93\u4e2d\u90fd\u80fd\u627e\u5230\u5b83\u3002\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5\u5b83\uff0c\u90a3\u73b0\u5728\u5c31\u6765\u5b89\u88c5\u4e00\u4e0b\u5427\u3002<\/p>\n
Debian\/Ubuntu<\/strong><\/p>\n Fedora<\/strong><\/p>\n Arch<\/strong><\/p>\n Gentoo<\/strong><\/p>\n \u4f60\u9700\u8981\u4e00\u4e2a\u5bc6\u94a5\u5bf9\u6765\u52a0\u89e3\u5bc6\u6587\u4ef6\u3002\u5982\u679c\u4f60\u4e3a SSH \u5df2\u7ecf\u751f\u6210\u8fc7\u4e86\u5bc6\u94a5\u5bf9\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5b83\u3002\u5982\u679c\u6ca1\u6709\uff0cGPG \u5305\u542b\u5de5\u5177\u6765\u751f\u6210\u5bc6\u94a5\u5bf9\u3002<\/p>\n GPG \u6709\u4e00\u4e2a\u547d\u4ee4\u884c\u7a0b\u5e8f\u53ef\u4ee5\u5e2e\u4f60\u4e00\u6b65\u4e00\u6b65\u7684\u751f\u6210\u5bc6\u94a5\u3002\u5b83\u8fd8\u6709\u4e00\u4e2a\u7b80\u5355\u5f97\u591a\u7684\u5de5\u5177\uff0c\u4f46\u662f\u8fd9\u4e2a\u5de5\u5177\u4e0d\u80fd\u8ba9\u4f60\u8bbe\u7f6e\u5bc6\u94a5\u7c7b\u578b\uff0c\u5bc6\u94a5\u7684\u957f\u5ea6\u4ee5\u53ca\u8fc7\u671f\u65f6\u95f4\uff0c\u56e0\u6b64\u4e0d\u63a8\u8350\u4f7f\u7528\u8fd9\u4e2a\u5de5\u5177\u3002<\/p>\n GPG \u9996\u5148\u4f1a\u8be2\u95ee\u4f60\u5bc6\u94a5\u7684\u7c7b\u578b\u3002\u6ca1\u4ec0\u4e48\u7279\u522b\u7684\u8bdd\u9009\u62e9\u9ed8\u8ba4\u503c\u5c31\u597d\u3002<\/p>\n \u4e0b\u4e00\u6b65\u9700\u8981\u8bbe\u7f6e\u5bc6\u94a5\u957f\u5ea6\u30024096<\/span> \u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n \u4e4b\u540e\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u8fc7\u671f\u7684\u65e5\u671f\u3002 \u5982\u679c\u5e0c\u671b\u5bc6\u94a5\u6c38\u4e0d\u8fc7\u671f\u5219\u8bbe\u7f6e\u4e3a 0<\/span>\u3002<\/p>\n \u7136\u540e\uff0c\u8f93\u5165\u4f60\u7684\u540d\u79f0\u3002<\/p>\n \u6700\u540e\uff0c\u8f93\u5165\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u3002<\/p>\n \u5982\u679c\u4f60\u9700\u8981\u7684\u8bdd\uff0c\u8fd8\u80fd\u6dfb\u52a0\u4e00\u4e2a\u6ce8\u91ca\u3002<\/p>\n \u6240\u6709\u8fd9\u4e9b\u90fd\u5b8c\u6210\u540e\uff0cGPG \u4f1a\u8ba9\u4f60\u6821\u9a8c\u4e00\u4e0b\u8fd9\u4e9b\u4fe1\u606f\u3002<\/p>\n GPG \u8fd8\u4f1a\u95ee\u4f60\u662f\u5426\u9700\u8981\u4e3a\u5bc6\u94a5\u8bbe\u7f6e\u5bc6\u7801\u3002\u8fd9\u4e00\u6b65\u662f\u53ef\u9009\u7684\uff0c \u4f46\u662f\u4f1a\u589e\u52a0\u4fdd\u62a4\u7684\u7a0b\u5ea6\u3002\u82e5\u9700\u8981\u8bbe\u7f6e\u5bc6\u7801\uff0c\u5219 GPG \u4f1a\u6536\u96c6\u4f60\u7684\u64cd\u4f5c\u4fe1\u606f\u6765\u589e\u52a0\u5bc6\u94a5\u7684\u5065\u58ee\u6027\u3002 \u6240\u6709\u8fd9\u4e9b\u90fd\u5b8c\u6210\u540e\uff0c GPG \u4f1a\u663e\u793a\u5bc6\u94a5\u76f8\u5173\u7684\u4fe1\u606f\u3002<\/p>\n \u73b0\u5728\u4f60\u62e5\u6709\u4e86\u81ea\u5df1\u7684\u5bc6\u94a5\uff0c\u52a0\u5bc6\u6587\u4ef6\u975e\u5e38\u7b80\u5355\u3002 \u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5728 \/tmp<\/span> \u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u6587\u672c\u6587\u4ef6\u3002<\/p>\n \u7136\u540e\u7528 GPG \u6765\u52a0\u5bc6\u5b83\u3002\u8fd9\u91cc -e<\/span> \u6807\u5fd7\u544a\u8bc9 GPG \u4f60\u60f3\u8981\u52a0\u5bc6\u6587\u4ef6\uff0c -r<\/span> \u6807\u5fd7\u6307\u5b9a\u63a5\u6536\u8005\u3002<\/p>\n GPG \u9700\u8981\u77e5\u9053\u8fd9\u4e2a\u6587\u4ef6\u7684\u63a5\u6536\u8005\u548c\u53d1\u9001\u8005\u3002\u7531\u4e8e\u8fd9\u4e2a\u6587\u4ef6\u7ed9\u662f\u4f60\u7684\uff0c\u56e0\u6b64\u65e0\u9700\u6307\u5b9a\u53d1\u9001\u8005\uff0c\u800c\u63a5\u6536\u8005\u5c31\u662f\u4f60\u81ea\u5df1\u3002<\/p>\n \u4f60\u6536\u5230\u52a0\u5bc6\u6587\u4ef6\u540e\uff0c\u5c31\u9700\u8981\u5bf9\u5b83\u8fdb\u884c\u89e3\u5bc6\u3002 \u4f60\u65e0\u9700\u6307\u5b9a\u89e3\u5bc6\u7528\u7684\u5bc6\u94a5\u3002 \u8fd9\u4e2a\u4fe1\u606f\u88ab\u7f16\u7801\u5728\u6587\u4ef6\u4e2d\u3002 GPG \u4f1a\u5c1d\u8bd5\u7528\u5176\u4e2d\u7684\u5bc6\u94a5\u8fdb\u884c\u89e3\u5bc6\u3002<\/p>\n \u5047\u8bbe\u4f60\u9700\u8981\u53d1\u9001\u6587\u4ef6\u7ed9\u522b\u4eba\u3002\u4f60\u9700\u8981\u6709\u63a5\u6536\u8005\u7684\u516c\u94a5\u3002 \u5177\u4f53\u600e\u4e48\u83b7\u5f97\u5bc6\u94a5\u7531\u4f60\u81ea\u5df1\u51b3\u5b9a\u3002 \u4f60\u53ef\u4ee5\u8ba9\u4ed6\u4eec\u76f4\u63a5\u628a\u516c\u94a5\u53d1\u9001\u7ed9\u4f60\uff0c \u4e5f\u53ef\u4ee5\u901a\u8fc7\u5bc6\u94a5\u670d\u52a1\u5668\u6765\u83b7\u53d6\u3002<\/p>\n \u6536\u5230\u5bf9\u65b9\u516c\u94a5\u540e\uff0c\u5bfc\u5165\u516c\u94a5\u5230 GPG \u4e2d\u3002<\/p>\n \u8fd9\u4e9b\u516c\u94a5\u4e0e\u4f60\u81ea\u5df1\u521b\u5efa\u7684\u5bc6\u94a5\u4e00\u6837\uff0c\u81ea\u5e26\u4e86\u540d\u79f0\u548c\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u7684\u4fe1\u606f\u3002 \u8bb0\u4f4f\uff0c\u4e3a\u4e86\u8ba9\u522b\u4eba\u80fd\u89e3\u5bc6\u4f60\u7684\u6587\u4ef6\uff0c\u522b\u4eba\u4e5f\u9700\u8981\u4f60\u7684\u516c\u94a5\u3002 \u56e0\u6b64\u5bfc\u51fa\u516c\u94a5\u5e76\u5c06\u4e4b\u53d1\u9001\u51fa\u53bb\u3002<\/p>\n \u73b0\u5728\u53ef\u4ee5\u5f00\u59cb\u52a0\u5bc6\u8981\u53d1\u9001\u7684\u6587\u4ef6\u4e86\u3002\u5b83\u8ddf\u4e4b\u524d\u7684\u6b65\u9aa4\u5dee\u4e0d\u591a\uff0c \u53ea\u662f\u9700\u8981\u6307\u5b9a\u4f60\u81ea\u5df1\u4e3a\u53d1\u9001\u4eba\u3002<\/p>\n \u5c31\u8fd9\u6837\u4e86\u3002GPG \u8fd8\u6709\u4e00\u4e9b\u9ad8\u7ea7\u9009\u9879\uff0c \u4e0d\u8fc7\u4f60\u5728 99% \u7684\u65f6\u95f4\u5185\u90fd\u4e0d\u4f1a\u7528\u5230\u8fd9\u4e9b\u9ad8\u7ea7\u9009\u9879\u3002 GPG \u5c31\u662f\u8fd9\u4e48\u6613\u4e8e\u4f7f\u7528\u3002\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u521b\u5efa\u7684\u5bc6\u94a5\u5bf9\u6765\u53d1\u9001\u548c\u63a5\u53d7\u52a0\u5bc6\u90ae\u4ef6\uff0c\u5176\u6b65\u9aa4\u8ddf\u4e0a\u9762\u6f14\u793a\u7684\u5dee\u4e0d\u591a\uff0c \u4e0d\u8fc7\u5927\u591a\u6570\u7684\u7535\u5b50\u90ae\u4ef6\u5ba2\u6237\u7aef\u5728\u62e5\u6709\u5bc6\u94a5\u7684\u60c5\u51b5\u4e0b\u4f1a\u81ea\u52a8\u5e2e\u4f60\u505a\u8fd9\u4e2a\u52a8\u4f5c\u3002<\/p>\n via: https:\/\/linuxconfig.org\/how-to-encrypt-and-decrypt-individual-files-with-gpg<\/a><\/p>\n \u4f5c\u8005\uff1aNick Congleton<\/a>[1]<\/span> \u8bd1\u8005\uff1alujun9972<\/a>[2]<\/span> \u6821\u5bf9\uff1awxy<\/a>[3]<\/span><\/p>\n \u672c\u6587\u7531 LCTT<\/a>[4]<\/span> \u539f\u521b\u7f16\u8bd1\uff0cLinux \u4e2d\u56fd<\/a>[5]<\/span> \u8363\u8a89\u63a8\u51fa<\/p>\n \u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-9118-1.html<\/a><\/p>\n$ sudo apt install gnupg\r\n<\/pre>\n
# dnf install gnupg2\r\n<\/pre>\n
# pacman -S gnupg\r\n<\/pre>\n
# emerge --ask app-crypt\/gnupg\r\n<\/pre>\n
$ gpg --full-generate-key\r\n<\/pre>\n
$ touch \/tmp\/test.txt\r\n<\/pre>\n
$ gpg -e -r \"Your Name\" \/tmp\/test.txt\r\n<\/pre>\n
$ gpg -d \/tmp\/test.txt.gpg\r\n<\/pre>\n
$ gpg --import yourfriends.key\r\n<\/pre>\n
gpg --export -a \"Your Name\" > your.key\r\n<\/pre>\n
$ gpg -e -u \"Your Name\" -r \"Their Name\" \/tmp\/test.txt\r\n<\/pre>\n
\n\n