Create a key:

gpg --gen-key

To export a public key:

gpg --armor --export name@example.com > public_key.asc

Export a public key into file public.key:

gpg --export -a "User Name" > public.key

Create a file called 'public.key' with the public key for User Name:

gpg --export -a "User Name"

Export a private key:

gpg --export-secret-key -a "User Name" > private.key

Import a public key:

gpg --import public.key/.asc

Decrypt the file:

gpg --decrypt file.pgp

Decrypt a GPG-encrypted file:

gpg --output original_message.txt --decrypt message.txt.gpg

Import a private key (not work everywhere):

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

Delete a public key (from your public key ring):

gpg --delete-key "User Name"

NOTE! If there is a private key on your private key ring associated with this public key, you will get an error! You must delete your private key for this key pair from your private key ring first.

Delete an private key (a key on your private key ring):

gpg --delete-secret-key "User Name"

List the keys in your public key ring:

gpg --list-keys

List the keys in your secret key ring:

gpg --list-secret-keys

To generate a new key pair:

gpg --full-generate-key

Sign a file using your private key:

gpg --sign message.txt

Verify a digital signature of a GPG-signed file:

gpg --verify message.txt.gpg

Generate a short list of numbers that you can use via an alternative method to verify a public key:
(This creates the file fingerprint with your fingerprint info.)

gpg --fingerprint > fingerprint

Encrypt data:

gpg -e -u "Sender User Name" -r "Receiver User Name" somefile

Encrypt a file using a recipient's public key:

gpg --encrypt --recipient recipient@example.com message.txt

Decrypt data:

gpg -d mydata.tar.gpg
gpg --edit-key
gpg --gen-revoke
  • Use Case *.1: Mentioned above were the commands for exporting and importing secret keys, and I want to explain one reason of why maybe you'd want to do this. Basically if you want one key-pair for all of your computers (assuming you have multiple computers), then this allows you export that key-pair from the original computer and import it to your other computers.

  • Use Case *.2: Mentioned above were the commands for exporting and importing secret keys, and I want to explain one reason of why maybe you'd want to do this. Basically, if you belonged to a group, and wanted to create a single key-pair for that group, one person would create the key-pair, then export the public and private keys, give them to the other members of the group, and they would all import that key-pair. Then a member of the group or someone outside could use the group public key, encrypt the message and/or data, and send it to members of the group, and all of them would be able to access the message and/or data. Basically you could create a simplified system where only one public key was needed to send encrypted stuffs to muliple recipients.

Resources: