Introduction
GnuPG, or GPG, is the open-source counterpart to the original Pretty Good Privacy (PGP) encryption system. It’s a robust tool for encrypting data and communications, and the de facto standard for this in Linux and other Unix-like systems.
Generating GPG Keys
To start using GPG, you need to create a key pair. The public key can be shared, while the private key remains with you.
- Open your terminal and enter:
gpg --gen-key
- Select the type of key (RSA and RSA is recommended).
- Choose the key size (2048 bits for most users, 4096 bits for higher security).
- Set the key expiration time (2–3 years recommended).
- Enter your name, email address, and a comment.
- Create a passphrase to protect your private key.
After this, you will have a GPG key pair.
Encrypting and Decrypting Files with GPG
To encrypt a file using the public key, use:
gpg -e -u "Your Name" -r "Recipient Name" file.txt
To decrypt a file, use:
gpg -o file_decrypted.txt -d file.txt.gpg
Show All Public Keys with GPG
To view all public keys in your keyring, use:
gpg --list-keys
Export Public Keys with GPG
To export a public key, use:
gpg --export -a --output "file_output_name".asc "Email address or Name"
GPG is a powerful tool for protecting your confidential information. While it can be complex for beginners, its flexibility and reliability make it a valuable tool for encryption needs.