How do I encrypt a sensitive file with just a password?

Quick Linux Tip #33:

Try: openssl enc -aes-256-cbc -pbkdf2 -in secrets.txt -out secrets.enc

Info: AES-256-CBC provides strong symmetric encryption. -pbkdf2 uses secure key derivation (automatically adding a salt) to prevent brute-force attacks.

Examples:

  • $ openssl enc -d -aes-256-cbc -pbkdf2 -in secrets.enc -out secrets.txt  # Decrypt
  • $ tar -czf - /home/data | openssl enc -aes-256-cbc -pbkdf2 -out backup.tar.gz.enc
  • $ gpg -c secrets.txt  # Simpler alternative using GPG

Note: Always securely delete the plaintext original after encrypting (shred -u secrets.txt). Avoid passing passwords inline via command arguments as they appear in process history.




LinuxTeck.com
linuxteck@ubuntu:~$ openssl enc -aes-256-cbc -pbkdf2 -in secrets.txt -out secrets.enc
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:

linuxteck@ubuntu:~$ ls -la secrets.*
-rw-r--r-- 1 linuxteck linuxteck 234 Jul 26 10:45 secrets.enc
-rw-r--r-- 1 linuxteck linuxteck 189 Jul 26 10:44 secrets.txt

linuxteck@ubuntu:~$ openssl enc -d -aes-256-cbc -pbkdf2 -in secrets.enc -out secrets.txt
enter aes-256-cbc decryption password:
linuxteck@ubuntu:~$

PREVIOUS ARTICLE Quick Linux Tip #32: How do I see everything a specific user is doing right now? NEXT ARTICLE Quick Linux Tip #34: How fast is my network really? Not just ping - actual throughput.
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.