Encrypting a file using OpenSSL
To encrypt a file, run
1 |
openssl enc -aes-256-cbc -in FILE -out FILE.enc |
To decrypt, use
1 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
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:~$ |