Encrypt multiple files at once

Since GnuPG doesn't support this directly, the way to do this would be to add another layer, e.g. using tar.

tar c project1.7z project2.7z | gpg --cipher-algo AES256 --compression-algo BZIP2 -co projects.gpg

And to extract:

gpg -d projects.gpg | tar x

You'll be left with project1.7z and project2.7z. Your script can then pick up where you left off.


Is there a way to pass multiple filenames to gpg to have it encrypt all of
them in one go?

No, there is not.

You will likely want to pass the passphrase with one of the following gpg options (the latter would be most secure choice):

--passphrase
--passphrase-file
--passphrase-fd

If you want to try something else then GPG there are other backup methods for encrypting multiple files:

original source: http://www.obsd.hu/docs/Unix-backup-with-aes.txt

vi ~/.bashrc

backup() {
if [[ "$1" = "" ]]; then echo 'specify full path' && exit 1; fi
CURRENTDATE="`date +%F-%Hh`"
echo 'Did you do a screenshot of the Desktop and backup all the Bookmarks of the webbrowser and backup cronjobs, etc...?'
read
echo "START: `date`"
ORIGDIR="$1"; ORIGDIRNORM="`echo $ORIGDIR | sed 's/\/$//g'`"; tar cvf - "${ORIGDIRNORM}/" 2>/dev/null | gzip -9 - 2>/dev/null | openssl aes-256-cbc -salt -out "${ORIGDIRNORM}-backup-${CURRENTDATE}.tar.gz.aes" && cksum "${ORIGDIRNORM}-backup-${CURRENTDATE}.tar.gz.aes" >> checksum.txt
echo "END: `date`"
}

decrypt() {
if [[ "$1" = "" ]]; then echo 'specify full path' && exit 1; fi
CURRENTDATE="`date +%F-%Hh`"
echo 'This will decrypt the backup in the current working directory, are you sure?'
read
echo "START: `date`"
ORIGDIR="$1"
openssl aes-256-cbc -d -salt -in "${ORIGDIR}" | tar -xz -f -
echo "END: `date`"
}

Usage: just use "backup DIRECTORY" for encryption and "decrypt DIRECTORY.tar.gz.aes"

Tags:

Gpg