logo
🐧 Linux 命令

GnuPG

GnuPG Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。

📂 分类 · Linux 命令🧭 Markdown 速查🏷️ 2 个标签
#gpg#encryption
向下滚动查看内容
返回全部 Cheat Sheets

Getting Started

Software

Gpg4win and the GPG Suite have OS-specific features.

Sometimes GPG keys are referred as PGP keys. They're interchangeable, as they follow the OpenPGP Standard.

Create a key-pair

Generate your keys:

SHELL
滚动查看更多
$ gpg --generate-key

... or fully configure your keys.

SHELL
滚动查看更多
$ gpg --generate-full-keys

Note: Choose a strong passphrase! The encryption is only as strong as your passphrase.

Key management

List your keys:

SHELL
滚动查看更多
$ gpg --list-keys

List your secret keys:

SHELL
滚动查看更多
$ gpg --list-secret-keys

Export your public key:

SHELL
滚动查看更多
$ gpg --export --armor <ID>

Export your secret key:

SHELL
滚动查看更多
$ gpg --export-secret-key --armor <ID>

Delete your public key:

SHELL
滚动查看更多
$ gpg --delete-key <ID>

Delete your secret key:

SHELL
滚动查看更多
$ gpg --delete-secret-key <ID>

Encryption

Symmetric

Encrypt with a passphrase:

SHELL
滚动查看更多
$ gpg -c <FILE>

Encrypt as ASCII with -a flag:

SHELL
滚动查看更多
$ gpg -ac <FILE>

Set output file path with -o flag:

SHELL
滚动查看更多
$ gpg -c <FILE> -o <PATH>

Decrypt with a passphrase:

SHELL
滚动查看更多
$ gpg <FILE>

Note: Choose a strong passphrase! The encryption is only as strong as your passphrase.

Asymmetric

Encrypt using public-private key encryption:

SHELL
滚动查看更多
$ gpg -e -r <RECIPIENT> <FILE>

Encrypt as ASCII output with -a flag:

SHELL
滚动查看更多
$ gpg -ea -r <RECIPIENT> <FILE>

Encrypt and sign with -s flag:

SHELL
滚动查看更多
$ gpg -se -r <RECIPIENT> <FILE>

Add multiple recipients:

SHELL
滚动查看更多
$ gpg -e -r <RECIPIENT1> -r <RECIPIENT2> <FILE>

Set output file path with -o flag:

SHELL
滚动查看更多
$ gpg -e -o <PATH> -r <RECIPIENT> <FILE>

Decrypt with your private key:

SHELL
滚动查看更多
$ gpg <FILE>

Replace <RECIPIENT> with your intended recipient's imported public key ID.

Importing a public key

Import using a file:

SHELL
滚动查看更多
$ gpg --import <FILE>

Import using a link (macOS/Linux):

SHELL
滚动查看更多
$ curl <WEBSITE> | gpg --import

Don't forget to sign the imported key:

SHELL
滚动查看更多
$ gpg --sign-key <ID>

Commit Signing

Local Git Setup

Enable GPG signing:

SHELL
滚动查看更多
$ git config --global commit.gpgsign true

Set the signing key:

SHELL
滚动查看更多
$ git config --global user.signingkey <ID>

Set location of GPG:

SHELL
滚动查看更多
$ git config --global gpg.program <PROGRAM>

Note: Your name and email must match on Git and GnuPG.

GPG Program List

Replace <PROGRAM> with one of the following:

PlatformValue
WindowsC:\Program Files (x86)\GnuPG\bin\gpg.exe
macOS/Linux/usr/local/bin/gpg

{.left-text}

Exporting your public key

Export as ASCII:

SHELL
滚动查看更多
$ gpg --export --armor <ID>

Note: Platforms, like GitHub, may ask you to verify the email you set in Git and GnuPG.

Windows: Add to Startup Apps

PowerShell Commands

When you do a full restart, the GPG agent might not automatically start. Add the GnuPG's IPC tool to Startup Apps using PowerShell:

SHELL
滚动查看更多
$ $shell = New-Object -ComObject WScript.Shell
$ $shortcut = $shell.CreateShortcut("C:\Users\$($Env:UserName)\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\gpg-connect-agent.lnk")
$ $shortcut.TargetPath = "C:\Program Files (x86)\GnuPG\bin\gpg-connect-agent.exe"
$ $shortcut.Arguments = "/bye"
$ $shortcut.Save()

Start up manually instead:

SHELL
滚动查看更多
$ gpgconf --launch gpg-agent

Check if it was successfully added here.

相关 Cheat Sheets

1v1免费职业咨询
logo

Follow Us

linkedinfacebooktwitterinstagramweiboyoutubebilibilitiktokxigua

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-airwallex.png/image/layout/pay-alipay.png

地址

Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)
Level 2, 171 La Trobe St, Melbourne VIC 3000
四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号
Business Hub, 155 Waymouth St, Adelaide SA 5000

Disclaimer

footer-disclaimerfooter-disclaimer

JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.

匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议

© 2017-2025 JR Academy Pty Ltd. All rights reserved.

ABN 26621887572