Unzipping Password Protected Files on Debian

First let me suggest that you should not password protect zip files.  GPG them or pick any other method than having to expose the private key in plain text.  It seems that 99% of the time that you receive a zip file with a password, the sender has included the password in the same email defeating the whole purpose anyway – however it is still an issue we have to deal with because for some reason some can only send you a password protected zip file.

If life was perfect, you would just add the ‘-p <password>’ to the default ‘unzip’ and magic would happen.

unzip -P reallysecretpassword MyLettersToSanta.zip

And this would work had you originally used the same utility in Linux to password protect the file (which you never would have done because you would have used GPG).

Turns out your file was saved and zipped on your new Windows machine so it used AES which is not supported by many old unzipping tools on Linux.  So when you try to decrypt the file with an older tool it throws an “unsupported compression method 99” error and you get nothing.

No worries though – there is a solution in the standard Debian repositories called 7z.  To get it:

sudo apt-get install p7zip-full

The syntax is different from your normal zip.  To unzip a password protected file, you would use the following command:
7z x -preallysecretpassword MyLettersToSanta.zip

Notice it is not ‘-x’ and there is no space between the option ‘-p’ and the password.  If you want to put your zipped files into a specific folder, you can add “-o./output”.  No spaces after “-o” and the path either.

One downside to running this command is your password is now probably saved in your shell history.  For most of us, you can edit your ~/.bash_history to delete your password.


Leave a Reply