Read more

Encrypt files using OpenSSL

Thomas Eisenbarth
February 18, 2011Software engineer at makandra GmbH

Using OpenSSL it's very easy to seriously encrypt files.
Use the script below. Input / Output are self explanatory. Put a long passphrase into PASSWORD_FILENAME. It is the key to decrypt to file again. Paste this into a console and copy it to wherever you need it.

touch /tmp/openssl_encryption_password && chmod 0700 /tmp/openssl_encryption_password && apg -n1 -m 60 > /tmp/openssl_encryption_password
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Remember to at least delete the input file afterwards. Better use shred to wipe files on Linux as used in the script below.

#!/bin/sh
PASSWORD_FILENAME=/opt/backup/openssl_encryption_password
INPUT_FILE=/opt/backup/input
OUTPUT_FILE=/opt/backup/output.enc

/usr/bin/openssl enc -aes-256-cbc -salt -in INPUT_FILE -out OUTPUT_FILE -pass file:$PASSWORD_FILENAME
/usr/bin/shred -u INPUT_FILE
Posted by Thomas Eisenbarth to makandra dev (2011-02-18 18:09)