You downloaded a self-custody wallet from the official website. How can you tell whether the installer is the one the project published? GPG answers that by verifying signatures. It also encrypts files and messages. This guide covers all three operations in practice on Linux or Ubuntu on WSL. You can practise in an isolated lab that keeps your real keys safe, or follow the steps for real use.
What GPG does
GPG relies on three concepts. Understand each one before running any commands.
Encryption protects the contents. To send a file to a friend, encrypt it with their public key. Only the corresponding private key can open it. Signing works the other way round. You sign with your private key, and anyone can verify the signature with your public key. The signature proves that the content came from that key and reveals any changes made afterwards. A signed file remains readable to anyone.
The fingerprint identifies the key. Anyone can enter a name and email address, so those details cannot establish identity. Before trusting a key, check the full fingerprint with its owner through an independent channel, such as a phone call or a meeting in person.
1. Choose where to practise: lab or real use
You run the same commands in the following sections in both modes. The environment you run them in is what changes.
Lab. Use this mode if it is your first time. You create a temporary, isolated key directory, which keeps your real keys out of the exercise. Run the block below and use the fictional names in the examples. Your files stay in the temporary folder that pwd shows at the end. When you finish, exit takes you back to your previous shell.
Real use. Skip the block below. Work in your usual shell with your regular keyring, in a working folder of your choice. In the following sections, replace the fictional name and email address with your own. Your backup and revocation certificate now matter in practice, so treat section 8 as part of your real setup.
In either mode, run gpg --version before you start. If it shows no version, install the gnupg package using the package manager for your Linux distribution.
The commands below prepare the lab by opening a new shell with an isolated key directory.
bash
umask 077
lab="$(mktemp -d)"
mkdir -m 700 "$lab/chaves"
export GNUPGHOME="$lab/chaves"
export GPG_TTY="$(tty)"
cd "$lab"
pwd
gpg --version
2. Generate your key
Enter your passphrase at the GPG prompt. It protects the private key stored on disk and is independent of the fingerprint. For real use, choose a long, unique passphrase. In the lab, use one you can remember until you finish the exercise. The example uses a fictional name. For real use, replace it with your own name and email address.
gpg --quick-generate-key 'Your Name <you@example.org>' default default 1y
gpg --list-keys --fingerprint
gpg --list-secret-keys --keyid-format LONG
Copy the full fingerprint of the primary key, shown immediately below the pub line. Leave the short key ID and the fingerprint of the subkey marked sub aside. The primary key identifies the key set. The encryption subkey usually has an [E] marker. You can keep the fingerprint in a variable because it is public.
read -r -p 'Full fingerprint of your key, no spaces: ' MINHA_CHAVE
gpg --list-keys "$MINHA_CHAVE"
3. Encrypt a file and recover its contents
For the first test, use your own key as the recipient. This lets you test the full cycle from encryption to decryption on your own. In section 5, you send a file to someone else after importing and checking their public key.
printf '%s\n' 'This message is just a test.' > exemplo.txt
gpg --output exemplo.txt.gpg --encrypt --recipient "$MINHA_CHAVE" exemplo.txt
gpg --output exemplo-restaurado.txt --decrypt exemplo.txt.gpg
sha256sum exemplo.txt exemplo-restaurado.txt
The test worked if decryption finished without an error and the two hashes match. To send the file to someone else and still be able to open it yourself, pass --recipient twice, once for them and once for you. Both of you can open the resulting file.
4. Send a message as text
The --armor option produces a block of text you can paste into a chat or email. In Bash, read -s hides what you type and keeps the content out of your command history. Type one line and press Enter.
read -rsp 'Test message: ' mensagem
printf '\n'
printf '%s' "$mensagem" | gpg --armor --encrypt --recipient "$MINHA_CHAVE" > mensagem.asc
unset mensagem
gpg --decrypt mensagem.asc
To receive a message, save the whole block, including the BEGIN and END lines, in a file such as recebida.asc and run gpg --decrypt recebida.asc. Keep secret messages out of echo and printf commands because the shell records those commands in its history. When you compose an email by hand, the encrypted block protects only the body. The subject and addresses stay visible.
5. Exchange public keys
To share your key, export only the public part. To accept someone else’s key, inspect the file they send you and compare the full fingerprint with the one they confirmed through another channel.
In real use, your friend sends you amigo-publica.asc and confirms the fingerprint separately. In the lab, the block below sets up a second key directory to simulate your friend’s side of the exchange. The last command shows their fingerprint, which you would receive through another channel in real use. Skip this block if you already have the file.
mkdir -m 700 "$lab/chaves-amigo"
GNUPGHOME="$lab/chaves-amigo" gpg --quick-generate-key 'Friend Example <friend@example.org>' default default 1y
GNUPGHOME="$lab/chaves-amigo" gpg --armor --export friend@example.org > amigo-publica.asc
GNUPGHOME="$lab/chaves-amigo" gpg --fingerprint friend@example.org
The next steps are the same in both modes. Run the commands one line at a time. Stop after --show-keys and compare the displayed fingerprint with the one your friend confirmed. Import the key only after the two match.
gpg --armor --export "$MINHA_CHAVE" > minha-publica.asc
gpg --show-keys --with-fingerprint amigo-publica.asc
gpg --import amigo-publica.asc
read -r -p 'Verified fingerprint of your friend: ' CHAVE_AMIGO
gpg --output para-amigo.gpg --encrypt --recipient "$CHAVE_AMIGO" exemplo.txt
GPG may warn that it cannot establish the link between the key and the identity and ask whether you want to use the key anyway. The warning serves a purpose. Answer y only after checking the fingerprint. Keep the check enabled. The public key file reveals the name and email addresses listed on the key and contains only public key material.
6. Sign a file and verify the signature
A detached signature works well for PDFs, software releases and lists of SHA-256 hashes. The recipient needs the original file, its signature and the signer’s verified public key.
gpg --armor --output exemplo.txt.sig.asc --local-user "$MINHA_CHAVE" --detach-sign exemplo.txt
gpg --verify exemplo.txt.sig.asc exemplo.txt
In --verify, put the signature first and the file second. A valid signature confirms that the content matches the signature made with that key. You still need to check who owns the key and whether the file is safe. When downloading a program, first verify the project’s key and the signature on its published manifest. Then compare the SHA-256 hash of your download with the manifest.
7. Choose the right operation
Each situation calls for a different operation. To send a private document, encrypt it with the recipient’s public key. To publish a release or a PDF anyone can read, create a detached signature and distribute it with the file. To keep the content private and prove it came from your key, combine --sign --encrypt. Select your key with --local-user and the recipient’s key with --recipient.
When you are working without exchanging keys, use gpg --symmetric --output exemplo-senha.gpg exemplo.txt. Anyone with the passphrase can open the file. Choose a strong passphrase and send it separately. To sign commits, configure Git to use your signing key. Support depends on the platform where you publish.
8. Back up and look after your key
For real use, keep the private key and revocation certificate in protected storage separate from the computer. Keep the passphrase somewhere safe as well. GnuPG usually creates the revocation certificate in openpgp-revocs.d inside the key directory. Publish it only if you intend to revoke the key. In the lab, run the commands to see how they work. You are working with test data.
gpg --armor --export-secret-keys "$MINHA_CHAVE" > minha-chave-privada.asc
This command exports private key material. For real use, write it directly to a protected location outside synced folders. Test recovery in a new key directory. Point GNUPGHOME to an empty folder with permissions set to 700, import the private backup with gpg --import and check that it opens a test file you encrypted before the export. If you lose the private key or cannot unlock it, you need more than a public key backup to recover your files.
To list the identities and signatures linked to your key, use gpg --check-sigs "$MINHA_CHAVE". To add an email address without changing the fingerprint, use gpg --quick-add-uid "$MINHA_CHAVE" 'Your Name <new-email@example.org>'. To change the primary identity, open gpg --edit-key "$MINHA_CHAVE". At the prompt, run list, select uid N, use primary and finish with save. If you have already shared a UID and need to invalidate it, revoke it. Deleting it from your local copy leaves the copies you shared in circulation. After any change, export the public key again to distribute the updated version.
9. Protect a folder without losing the originals
GPG works on individual files. To protect a whole folder as a single package, create a .tar archive and encrypt it. The intermediate .tar remains unencrypted until you delete it. If you prefer a separate .gpg for each file, write a script that preserves the originals, skips files that are already encrypted and leaves existing output files intact.
Before deleting any original, make four checks. Confirm that the batch finished without errors. Compare the SHA-256 hash of each original with that of the decrypted content. Test recovery using your key backup. Confirm that the encrypted copies reached their destination. If you use gpg --decrypt arquivo.gpg | sha256sum in Bash, enable set -o pipefail and check the exit status as well as the printed hash.
Running rm is only the first step. It removes the file from the filesystem, but copies can remain on SSDs, in snapshots, recycle bins or sync histories. To keep unencrypted content out of a synced folder, encrypt the file before putting it there.
What this has to do with self-custody
In self-custody, you are responsible for checking that the installer is genuine. A good way to practise is to verify the signature of a program you already use, following the project’s official procedure, without touching your funds. Your wallet still needs its own seed backup. Keep all real secrets, including your seed and wallet passphrase, out of these tests.
References
GnuPG manual: key management · GnuPG manual: encryption and signatures