GPG daily usage
basic construction to use gpg
GPG/GnuPG aka Gnu Privacy Guard is a encryption tool for email, git etc.
In this article will show you the basic usage of GPG
to ensure the passphrase can prompt in the terminal, export the following env var
GPG_TTY="$(tty)"
export GPG_TTY
basic command to use GPG
# generate the pair key
gpg --full-gen-key
# list private key
gpg --list-secret-keys
# list public key
gpg --list-keys
back and store the GPG keys
backup
- list all key and find out which one do you want to back up
gpg --list-secret-keys --keyid-format LONG
#sec rsa4096 2021-11-17 [SC] [expires: 2031-11-15]
# E7384A7902979AFAA3F2AC9EB1D896545257905D
#uid [ultimate] Kelvin Li <kelvin@memodir.com>
#ssb rsa4096 2021-11-17 [E] [expires: 2031-11-15]
- export the GPG key.
this command will export all neceessary key data for restore this key
gpg -o kelvin@memodir.com-key.gpg --export-options backup --export-secret-keys kelvin@memodir.com
enter the private key's passphrase in the prompt dialog to finish exporting key.
- transport the key to the server/computer you want to restore
restore
- import the key
gpg --import-options restore --import kelvin@memodir.com-key.gpg
- enter the passphrase to import the key
- edit the key
gpg --edit-key --import kelvin@memodir.com-key.gpg
# enter 'trust' to modify the trust value of the key
gpg > trust
# select 5 to trust ultimately
# finally confirm to input 'Y'
# quit to exit the edit mode
gpg> quit
now you should already import GPG key