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:
brew install gnupg
Linux:
sudo apt install gnupg
Windows:
winget install GnuPG.GnuPG
Create a Test File
Make something worth protecting. A secret message:
echo "The password for the server is: xk9#mP2zLq" > secret.txt
Check it:
cat secret.txt
Encrypt the File
gpg --symmetric --cipher-algo AES256 secret.txt
What each flag means:
gpg— the encryption tool--symmetric— use a password (as opposed to public/private keys). Same password encrypts and decrypts.--cipher-algo AES256— use AES-256 encryption, a military-grade algorithm trusted globally
Try to read the encrypted file:
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:
gpg-connect-agent reloadagent /bye
gpg-connect-agent reloadagent /bye
gpg-connect-agent killagent /bye
gpg-connect-agent /bye
Decrypt the File
Now bring your secret back:
gpg --decrypt secret.txt.gpg
Enter your password. The original message appears in the terminal. To save it to a file:
gpg --decrypt secret.txt.gpg > secret.txt
Read it:
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
- Journalists encrypt files before sending them to sources. If intercepted, the file is useless.
- Companies encrypt customer data so a breach reveals gibberish, not credit card numbers.
- Anyone encrypts their hard drive (macOS FileVault, Windows BitLocker) using the same AES encryption you just ran.