Script for using AesCrypt on a lot of files

0

I'm just learning bash and I'm about to renew my backup security standards at home, just in case something happens.

I have two external HDDs for Backup. I want to encrypt the files first on my laptop (which has a disk encryption applied to) and then move them to the HDD's so that there is no hidden (deleted) unencrypted data on there.

I could simply use a Disk Encryption but that's not what I intend to do for several reasons.

Beside that, how does a script looks like which encrypts all files (not the folders itself) down to the last subfolder from a given root folder using AESCrypt oder maybe something similar with AES-256-CBC?

user646056

Posted 2016-09-27T20:35:25.523

Reputation: 1

So you want only the files on the 2nd drive to be encrypted not the drive? if so a simple rsync -raXxHhD /drive_1 /drive_2 --exclude=/path/to/{contents_of_excludes.txt} – linuxdev2013 – 2016-09-29T12:04:05.073

Thanks, now I just have to encrypt the files beforehand. I wasn't aware of this command before – user646056 – 2016-09-30T22:46:16.807

If you are wanting to keep all the encrypted bits as is use dd – linuxdev2013 – 2016-10-02T13:58:49.943

Answers

1

I'm not quite sure you can use pure bash to encrypt. I'm sure it's possible, but I can offer another solution for you.


Bash Solution:

openssl enc -nosalt -aes-128-cbc -in test -out test.enc -p

Found this at stack-overflow here


Python Solution:

Instead of trying to stumble around bash, looking for a way to encrypt, have you tried looking at Python? A native Linux language, that supports encryption and many other things.

So in python, to do what you're looking to do.

apt-get install python-pip
pip install pyCrypto

Then from there, there's some things you're going to want to look at.

AES Encryption in Python

You're also going to want to look into the function "Walk" from the "OS" module.

OS Walk Example

And finally to make it so you can easily access your files with a simple password of your choice

#!/bin/python
# Python 2 example
from Crypto.Hash import MD5
secret = MD5.new(raw_input('Password: ')).hexdigest()

Then simply encrypt with secret every file if you choose, and the key will be the same for each file.

Skarlett

Posted 2016-09-27T20:35:25.523

Reputation: 105

This one comes in handy as I need to learn Python in the next couple of months! I think I can combine that with Rsync somehow to fully automate the process of encrypting and copying. Maybe I don't even need to use Rsync and can solve it solely with Python. – user646056 – 2016-09-30T22:50:06.137

@user645056 Yes python can be used solely to create such a program by using sockets and the other libraries I listed above. If you're looking to backup and encrypt data, there's a program called spider oak – Skarlett – 2016-10-02T09:43:34.783