github twitter
GnuPG 2 on Ubuntu
Aug 23, 2014
2 minutes read

Installing

GnuPG is a complete and free implementation of the OpenPGP standard as defined by RFC4880 (also known as PGP). In addition to the source code being available, GPG also lives in Ubuntu’s repositories.

sudo aptitude install gnupg2

Generating a private key

gpg2 --gen-key

The private key is stored in ~/.gnupg/secring.gpg.

Key management

Exporting keys

The -armor option exports the keys in ASCII format instead of binary.

Public key

gpg2 --armor --output public.key --export 'User Name'

Private key

gpg2 --armor --output private.key --export-secret-key -a 'User Name'

Importing keys

Public key

gpg2 --import public.key

Private key

gpg2 --allow-secret-key-import --import private.key

Deleting keys

Private key

gpg2 --delete-secret-key 'User Name'

Public key

gpg2 --delete-key 'User Name'

Listing keys

Private keys

gpg2 --list-secret-keys

Public keys

gpg2 --list-keys

Encrypting/Decrypting files

Using a password

Encrypting

gpg2 --cipher-algo AES256 --symmetric example_file.txt

Decrypting

gpg2 example_file.txt.gpg

Using a key

For personal use

Encrypting

gpg2 -e -r 'Your Name' example_file.txt

Decrypting

gpg2 example_file.txt.gpg

You will be prompted to enter the password that you used to protect your private key when you created it (if you used one).

For someone else

Encrypting

gpg2 -e -r 'Your Name' example_file.txt

You’ll need to have already imported their public key before you can encrypt a file for them.

Decrypting

gpg2 example_file.txt.gpg

Only the recipient’s private key will be able to decrypt the encrypted file.

References


Back to posts


comments powered by Disqus