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
add comment

2 Answers

up vote 2 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):

share|improve this answer
add comment

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
add comment

Your Answer


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.