I can compress a 7zip archive with encryption like this:

7z a -pSECRET example.7z *.doc

But in this case I specify the password (SECRET) literally on the command line.

Is it also possible to specify a filename that contains the password? E.g. something like this:

7z a -p@passwordfile.txt example.7z *.doc

Except this doesn't work, in this case it will encrypt the archive literally using the password '@passwordfile.txt'.

Is there another way to go about this?

  • -p"$(cat passwordfile.txt)", or maybe (read secret < passwordfile.txt; 7z a -p"$secret" example.7z *.doc)
    – Tom Yan
    May 14 at 9:04
  • @TomYan Thanks but that way the password still becomes literally included in the actual command line. If I'd do ps -aux | grep 7z in another shell while it's encrypting, it shows the password there. And possibly it's even being logged in ~/.bash_history. I was hoping for a possibility of 7z itself to specify a password in a file, but maybe such a feature simply isn't there?
    – RocketNuts
    May 14 at 20:52
  • 1
    @RocketNuts For a couple other potential ways/ideas linuxquestions.org/questions/linux-software-2/… and howtogeek.com/734838/… May 15 at 2:18
  • This might help: superuser.com/a/1358942/340330
    – Cyrus
    May 15 at 21:53


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.