This simple yet powerful Bash script allows you to securely encrypt and decrypt files using GPG (GNU Privacy Guard) with a passphrase.
Perfect for cybersecurity beginners, ethical hackers, or privacy-conscious users who want a quick CLI tool to protect sensitive files.
β
Encrypt any file with GPG
β
Decrypt any .gpg
encrypted file
β
User-friendly menu
β
Minimal and clean Bash scripting
β
Great for learning encryption basics
Create a new file and paste the script:
touch test.sh
nano test.sh
Paste Code in it ( test.sh )
Make the script executable:
chmod +x test.sh
- π Run the Script
./test.sh
Choose one of the options:
1 to encrypt a file using a passphrase.
2 to decrypt a .gpg file using the passphrase.
π¦ Example
β Encrypt
./test.sh
Encrypt or Decrypt
1. Encrypt File
2. Decrypt File
Enter Choice: 1
Choose File to Encrypt: secrets.txt
β‘οΈ Youβll be prompted for a passphrase. GPG will create secrets.txt.gpg.
π Decrypt
./test.sh
Encrypt or Decrypt
1. Encrypt File
2. Decrypt File
Enter Choice: 2
Choose File to Decrypt (.gpg): secrets.txt.gpg
β‘οΈ Enter the same passphrase to decrypt. The original content will display in the terminal.
Keep your passphrase strong and secret π
Do not delete the original file manually before testing the .gpg file
This script uses symmetric encryption (gpg -c), which is simple and fast