Last active
May 10, 2021 14:23
-
-
Save danhodge/76ec25008d9492596ab3a0947b37de03 to your computer and use it in GitHub Desktop.
GPG Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You need to add a GPG public key to your local keyring before you can use it (located in ~/.gnupg) | |
# You can specify a custom keyring file using the option --keyring <full_path_to_keyring> | |
# For commands that operate on the keyring (such as import, list, etc.) you also need to include --no-default-keyring to | |
# tell GPG to not look at/modify the default keyring | |
gpg --import <key> | |
# Generate key and add it to your default keyring | |
gpg --gen-key | |
# Encrypt - selects the key based on the recipient email (will be shown when you import the key) | |
gpg --output <outfile.gpg> --encrypt --recipient <recipient_email> <input_file> | |
# Encrypt - suppress warnings about key provenance | |
--trust-model always | |
# Decrypt | |
gpg --output <decrypted_file> --decrypt <input_file.pgp> | |
# Decrypt from stdin with passphrase | |
cat <file> | gpg --batch --yes --passphrase=<passphrase> --pinentry-mode loopback --output file.dec --decrypt | |
# --- Using custom keyrings --- | |
# This will use put all of the keyring files in the specified directory (using the default GPG keyring file naming conventions for the files) | |
# Note that this directory should only be readable/writable/executable by the current user | |
gpg --homedir <full_path_to_dir> | |
# If you want to change GPG to write keys to specific file names, use --homedir + --keyring <filename> and --secret-keyring <filename> | |
# Always include --no-default-keyring when performing operations using a non-standard keyring file | |
# Export public key in base64 format from custom keyring file | |
gpg --armor --keyring <full_path_to_keyring> --export <key_id> > key.pub | |
# Export private key in base64 format from custom keyring file | |
gpg --armor --keyring <full_path_to_keyring> --export-secret-key <key_id> > key.priv | |
# Import public key into custom keyring file | |
gpg --no-default-keyring --keyring <full_path_to_keyring> --import <path_to_key> | |
# Import private key into custom keyring file | |
gpg --no-default-keyring --keyring <full_path_to_keyring> --allow-secret-key-import --import <path_to_key> | |
# Restart GPG agent | |
gpgconf --kill gpg-agent | |
gpg-agent --homedir $HOME_DIR/.gnupg --use-standard-socket --daemon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment