encryption with gpg

Generate key

$ gpg --gen-key

List keys

$ gpg --list-keys

Encrypt Data

With a passprhare

$ gpg -ca -o output.txt.gpg input.txt

with a certificate and from STDOUT

$ gpg -ea

or if you know the name already (can be key, name or email)

$ gpg -ea -r "Ahmy"

Decrypt Data

$ gpg -d file.txt.gpg


Public key

$ gpg --export -a "name" > public.key

-a is to create armored ascii output.

Private Key

$ gpg --export-secret-key -a "name" > private.key


Public key

$ gpg --export-secret-key -a "name" > private.key

Private Key

$ gpg --allow-secret-key-import --import private.key


Public Key

$ gpg --delete-key "Real Name"

Private Key

$ gpg --delete-secret-key "Real Name"

Extend the expiration

gpg --edit-key "name"

Select the key to extend

gpg> key 1
gpg> expire

Send key to a key server

gpg --keyserver keyserver.ubuntu.com --send-key "name"

Last updated