You need to send an accounting export, a backup archive, or an HR document to a specific person. The password sent in a separate email does not last long against a compromised inbox or a clumsy transfer. GPG on Linux encrypts the file with the recipient’s public key. Only they can open it with their private key and passphrase.
Before the first send, take the time to verify the complete fingerprint of the key and decrypt a test copy. Encryption does not replace a backup: if the private key disappears, the encrypted file remains unusable.
Check the key before encrypting
On Debian or Ubuntu, install GnuPG with sudo apt install gnupg. Fedora uses sudo dnf install gnupg2. Start by checking if you already have a public key for the concerned person:
gpg --list-keys --with-fingerprint "[email protected]"
If they have sent you a public-key.asc file, import it, then display its fingerprint again:
gpg --import public-key.asc
gpg --fingerprint "[email protected]"
Do not validate a key just because the name or email address seems plausible. Compare the complete fingerprint with the recipient using a separate channel, such as a phone call or an already authenticated messaging service. The official GPG manual reminds us that the tool handles keys, but cannot decide for you whether the key received actually belongs to the right person.
You also need your own pair of keys if you need to decrypt the file later. Run gpg --full-generate-key, choose a strong passphrase, and verify its presence:
gpg --full-generate-key
gpg --list-secret-keys --keyid-format LONG
Keep the fingerprint of your key, not just its short identifier. Short identifiers can look too similar and are not sufficient for serious verification.
Encrypt a copy, then actually try to open it
Start with a non-sensitive copy. Replace the fingerprint below with the one you have checked. Using the fingerprint avoids mistakenly choosing another key with the same name.
cp report.pdf report-test.pdf
gpg --output report-test.pdf.gpg
--encrypt
--recipient 0123456789ABCDEF0123456789ABCDEF01234567
report-test.pdf
The report-test.pdf.gpg file can be sent. The source file report-test.pdf remains readable on your machine. Do not leave it in a shared directory, a synchronization folder, or as an accidentally sent attachment.
Then decrypt to a different name. GPG will ask you for the passphrase of your private key if it is protected.
gpg --output restored-report.pdf
--decrypt report-test.pdf.gpg
Check that the restoration is identical to the source. A SHA-256 hash provides a simple proof, detailed in our guide sha256sum on Linux.
sha256sum report-test.pdf restored-report.pdf
cmp --silent report-test.pdf restored-report.pdf && echo "identical copy"
Both sums must match and cmp should display identical copy. If GPG cannot find the secret key or requests a passphrase that no one knows, stop there. Encrypting the final file will not solve this problem.
Keep the private key off the workstation
Export your private key only to an encrypted medium and keep it separate from the workstation. Never attach this file to the encrypted archive and do not upload it to the cloud without additional protection.
gpg --armor --export-secret-keys
0123456789ABCDEF0123456789ABCDEF01234567
> private-key-backup.asc
chmod 600 private-key-backup.asc
The exported file remains extremely sensitive, even protected by the passphrase of the key. Copy it to the designated medium, check that it is readable, and then remove it from the working directory. The official documentation states that ~/.gnupg contains files that only GnuPG should handle: avoid copying internal files randomly instead of an explicit export.
Also keep an offline note that indicates the fingerprint, the medium where the backup is located, and the person authorized to use it. Without the private key and passphrase, there is no recovery command.
Before the final send
- the recipient’s fingerprint has been verified through a second channel;
- the command uses this fingerprint, not a similar name;
- a test copy has been decrypted and compared to the source file;
- your private key and passphrase have an off-site backup;
- the clear source file does not leave in the same transfer as the
.gpgfile.
For a first exchange, I would choose a small test PDF and an available recipient to confirm the opening. Once this check is passed, use exactly the same command for the final file. Do not change the key, output path, or recipient at the last moment.