Encrypt a File in 30 Seconds with GPG

What is GPG?

GPG (GNU Privacy Guard) is a free, open-source tool that encrypts files so only someone with the password can read them.

Install GPG

macOS:

macOS
brew install gnupg

Linux:

Linux
sudo apt install gnupg

Windows:

Windows
winget install GnuPG.GnuPG

Create a Test File

Make something worth protecting. A secret message:

bash
echo "The password for the server is: xk9#mP2zLq" > secret.txt

Check it:

bash
cat secret.txt

Encrypt the File

bash
gpg --symmetric --cipher-algo AES256 secret.txt

What each flag means:

Try to read the encrypted file:

bash
cat secret.txt.gpg

Gibberish. Unreadable. That's what an attacker sees. Without the password, it's mathematically impossible to reverse.

Now, delete the original!

Clear the cache:

macOS
gpg-connect-agent reloadagent /bye
Linux
gpg-connect-agent reloadagent /bye
Windows (PowerShell)
gpg-connect-agent killagent /bye
gpg-connect-agent /bye

Decrypt the File

Now bring your secret back:

bash
gpg --decrypt secret.txt.gpg

Enter your password. The original message appears in the terminal. To save it to a file:

bash
gpg --decrypt secret.txt.gpg > secret.txt

Read it:

bash
cat secret.txt

Symmetric vs Asymmetric Encryption

Symmetric Encryption contains one password, shared between sender and receiver. It's fast and simple.

Asymmetric encryption uses two keys: a public key (anyone can encrypt with it) and a private key (only you can decrypt).

How reliable is AES-256

AES-256 is the encryption standard used by the US government. Cracking it by brute force — trying every possible key combination — would take billions of years.

The weak link, though, isn't the encryption. It's the password. If you use password123, it doesn't matter that AES-256 is unbreakable — an attacker will just guess the password.

Real-World Uses