Encrypting a file using OpenSSL

To encrypt a file, run

openssl enc -aes-256-cbc -in FILE -out FILE.enc

To decrypt, use

openssl enc -d -aes-256-cbc -in FILE.enc -out FILE

You can use -k option to provide password in commend line itself so it won’t prompt for password.

Here is a script i use to take backup

boby@hon-pc-01:~$ cat ~/bin/backup-my-files 
#!/bin/bash

cd $HOME/work/
rm -f myfiles.tar.gz myfiles.tar.gz.openssl
tar --exclude='MY_FILES/.git' -zcvf myfiles.tar.gz MY_FILES
openssl enc -aes-256-cbc -in /home/boby/work/myfiles.tar.gz -out myfiles.tar.gz.openssl

echo "Backup available in folder $HOME/work"
echo "You can decrypt file using"
echo ""
echo "openssl enc -d -aes-256-cbc -in myfiles.tar.gz.openssl -out myfiles.tar.gz"

boby@hon-pc-01:~$ 

openssl

Encrypt

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *