I need to create a shell script wherein I will unzip a password protected zip file. I know the password, and need to automate the unzip process.
How can I achieve this using Unix shell scripting?
You can use the unzip or tar command to extract (unzip) the file on Linux or Unix-like operating system. Unzip is a program to unpack, list, test, and compressed (extract) files and it may not be installed by default.
If you put the files you'd like to protect in a zip file, you can then apply a password. In Windows Explorer, highlight and right-click on the files you would like to put into a zipped file. Select Send to, then Zip folder (compressed). Double-click the zipped file, then select File and Add Password.
But, there are multiple methods to crack a password protected zip file to access its content. Cracking of passwords requires a lot of your time depending upon the length and complexity of the password when using the Brute-force method, which we are using for the current tutorial.
To unzip the example above, you can right-click on the MyImageData. zip. 001 file (after you've installed 7-Zip), select the 7-Zip menu, and then choose one of the "extract" options.
unzip -P your-password zipfile.zip
man unzip
-P password
use password to decrypt encrypted zipfile entries (if any). THIS IS INSECURE! Many multi-user operating systems provide ways for any user to see the current command line of any other user; even on stand-alone systems there is always the threat of over-the-shoulder peeking. Storing the plaintext password as part of a command line in an automated script is even worse. Whenever possible, use the non-echoing, interactive prompt to enter passwords. (And where security is truly important, use strong encryption such as Pretty Good Privacy instead of the relatively weak encryption provided by standard zipfile utilities.)
In Ubuntu, I've to install 7zip (7z) archive tool using following command:
sudo apt-get install p7zip-full
Then, you can use Ubuntu's default Archive Manager to unzip the password protected zip files
I ran into problem using unzip
saying need PK compat. v5.1 (can do v4.6)
.
Installed p7zip
instead and unzipped using following command:
7z x archive.zip -ppassword
To unzip multiple password protected files, this command WILL NOT WORK
unzip -P PASSWORD *.zip
To make it work, you need to include the *.zip
in quotes because whenever you use a wildcard (*), the shell itself will expand that and pass the results to the program. This is because, unlike most programs in UNIX, unzip cannot take more than one file at a time.
Read more here https://chrisjean.com/unzip-multiple-files-from-linux-command-line/.
Therefore, to unzip multiple protected files, use this
unzip -P PASSWORD '*.zip'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With