Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm writing a script which creates project archives and then creates 7z archives of them to make it easier on me to save specific versions and keep encrypted backups.

After I've generated the archives and I get to the encryption phase, I'd like to encrypt the files with one call to gpg if possible, so as to only have the user input their passphrase once. Otherwise, we'd either have to cache the user's passphrase in memory (which I'd really like not to do) or have them input and confirm their passphrase for every single project that is archived (which is worse).

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

If I try this:

$ gpg --cipher-algo AES256 --compression-algo BZIP2 -c project1.7z project2.7z

...I see the following error in the shell:

usage: gpg [options] --symmetric [filename]

Is there a way to do what I'm looking to accomplish?

share|improve this question
    
Why are you first using 7zip (presumably) to compress, then telling GnuPG to compress again using bzip2? I don't see that gaining you much in terms of space efficiency, and I do see it costing a good deal of CPU. –  Michael Kjörling May 13 at 20:50

4 Answers 4

up vote 3 down vote accepted
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
share|improve this answer

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.

share|improve this answer

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"

share|improve this answer

Yes there is an easy way:

for x in *; do 
  gpg -r (yourencrytionkey.com) -o $x.pgp -e $x
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.