Skip to content

Instantly share code, notes, and snippets.

@pedromadureira000
Last active September 6, 2022 20:40
Show Gist options
  • Save pedromadureira000/21dc53b5349fbcb4c420e7519032b752 to your computer and use it in GitHub Desktop.
Save pedromadureira000/21dc53b5349fbcb4c420e7519032b752 to your computer and use it in GitHub Desktop.
GPG

symmetric

Encrypt

gpg --symmetric meu_texto.txt

Decrypt

gpg --output meu_texto.txt --decrypt meu_texto.txt.gpg

asymmetric

create gpg key

gpg --full-generate-key

encrypt something

gpg -r myrecipient@domain.com.br -e file_i_want_to_encrypt

decrypt gpg file

gpg -d file.gpg

list keys

gpg --list-keys

delete key

gpg --delete-secret-keys "keyname"  (delete secret key)
gpg --delete-key "keyname" (delete public key)

unlock

gpg-agent

Export the public GPG key.

gpg --export -a contato@domain.com.br  > contato@your_gpg.pub

Export the private GPG key.

  1. First way
gpg --export-secret-keys --armor key_name > /path/to/secret-key-backup.asc
  1. Second way
gpg -o private.gpg --export-options backup --export-secret-keys contato@domain.com.br
  • OBS: This invocation places the key in the file private.gpg in the current directory. The export option backup exports all necessary data for GnuPG to restore the key.

Restore

  1. Import the private key.
gpg --import-options restore --import private.gpg

This invocation imports the key from the file private.gpg in the current directory. The import option restore imports all necessary data for GnuPG to fully restore the key. The import option keep-ownertrust keeps the owner trust of the key instead of clearing it’s trust value. This saves having to manually set the trust value for the key later.

  1. Enter the private key’s passphrase in the [Import Passphrase Prompt] to import the key
  2. Now, edit the freshly imported key.
gpg --edit-key contato@domain.com.br
gpg> trust
Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y
gpg> quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment