From 741065e4385ac75f268e10f5d18abf25dbdf36d1 Mon Sep 17 00:00:00 2001 From: Carlos Valdez Date: Fri, 10 Jan 2025 18:23:27 -0800 Subject: [PATCH] docs(gnupg): add initial GnuPG cheatsheet I'd like to research signing documents with GnuPG to add to this cheatsheet. --- README.md | 1 + source/_posts/gnupg.md | 230 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+) create mode 100644 source/_posts/gnupg.md diff --git a/README.md b/README.md index ee75770..d0a5ae2 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ Reference provides cheat sheets for the following: involved in using the command line program grep and assumes you already understand its usage. - [Netcat](https://cheatsheets.zip/nc.html): This cheat sheet provides various for using netcat on both Linux and Unix. - [Taskset](https://cheatsheets.zip/taskset): This quick reference cheat sheet for tasket command. +- [GnuPG](https://cheatsheets.zip/gnupg): A cheatsheet for GnuPG, the encryption and signing software.
diff --git a/source/_posts/gnupg.md b/source/_posts/gnupg.md new file mode 100644 index 0000000..fcd4c5c --- /dev/null +++ b/source/_posts/gnupg.md @@ -0,0 +1,230 @@ +--- +title: GnuPG +categories: + - Linux Command +intro: + A cheatsheet for GnuPG, the encryption and signing software. +--- +## Getting Started + +### Software + +Gpg4win and the GPG Suite have OS-specific features. + +* [GnuPG](https://gnupg.org/) +* [Gpg4win](https://www.gpg4win.org/) (Windows) +* [GPG Suite](https://gpgtools.org/) (macOS) + +Sometimes GPG keys are referred as PGP keys. They're interchangeable, as they follow the [OpenPGP Standard](https://www.rfc-editor.org/rfc/rfc9580.html). + +### Create a key-pair + +Generate your keys: + +```shell script +$ gpg --generate-key +``` + +... or fully configure your keys. + +```shell script +$ gpg --generate-full-keys +``` + +**Note:** Choose a strong passphrase! The encryption is only as strong as your passphrase. + +### Key management + +List your keys: + +```shell script +$ gpg --list-keys +``` + +List your secret keys: + +```shell script +$ gpg --list-secret-keys +``` + +Export your public key: + +```shell script +$ gpg --export --armor +``` + +Export your secret key: + +```shell script +$ gpg --export-secret-key --armor +``` + +Delete your public key: + +```shell script +$ gpg --delete-key +``` + +Delete your secret key: + +```shell script +$ gpg --delete-secret-key +``` + +## Encryption + +### Symmetric + +Encrypt with a passphrase: + +```shell script +$ gpg -c +``` + +Encrypt as ASCII with `-a` flag: + +```shell script +$ gpg -ac +``` + +Set output file path with `-o` flag: + +```shell script +$ gpg -c -o +``` + +Decrypt with a passphrase: + +```shell script +$ gpg +``` + +**Note:** Choose a strong passphrase! The encryption is only as strong as your passphrase. + +### Asymmetric + +Encrypt using public-private key encryption: + +```shell script +$ gpg -e -r +``` + +Encrypt as ASCII output with `-a` flag: + +```shell script +$ gpg -ea -r +``` + +Encrypt and sign with `-s` flag: + +```shell script +$ gpg -se -r +``` + +Add multiple recipients: + +```shell script +$ gpg -e -r -r +``` + +Set output file path with `-o` flag: + +```shell script +$ gpg -e -o -r +``` + +Decrypt with your private key: + +```shell script +$ gpg +``` + +Replace `` with your intended recipient's [imported public key](#importing-a-public-key) ID. + +### Importing a public key + +Import using a file: + +```shell script +$ gpg --import +``` + +Import using a link (macOS/Linux): + +```shell script +$ curl | gpg --import +``` + +Don't forget to sign the imported key: + +```shell script +$ gpg --sign-key +``` + +## Commit Signing + +### Local Git Setup + +Enable GPG signing: + +```shell script +$ git config --global commit.gpgsign true +``` + +Set the signing key: + +```shell script +$ git config --global user.signingkey +``` + +Set location of GPG: + +```shell script +$ git config --global gpg.program +``` + +**Note:** Your name and email must match on Git and GnuPG. + +### GPG Program List + +Replace `` with one of the following: + +| Platform | Value | +| ----------- | ------------------------------------------ | +| Windows | `C:\Program Files (x86)\GnuPG\bin\gpg.exe` | +| macOS/Linux | /usr/local/bin/gpg | + +{.left-text} + +### Exporting your public key + +Export as ASCII: + +```shell script +$ gpg --export --armor +``` + +**Note:** Platforms, like GitHub, may ask you to verify the email you set in Git and GnuPG. + +## Windows: Add to Startup Apps {.cols-1} + +### 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 script +$ $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 script +$ gpgconf --launch gpg-agent +``` + +Check if it was successfully added [here](ms-settings:startupapps).