3

Want to protect my ZIP archive with password.

Create archive with this:

zip -er archivename.zip file 

and get this:

Enter password: Verify password: 

Everything is ok,but I have variable with password and need to send this password to zip. Tried through arguments like this, but failed.

echo "$1"| zip -er archivename.zip file 

Is it possible in bash? Because zip utility does not support stdin.

2 Answers 2

6

Read the man

For insecure solution, use -P:

-P|--password password Use password to encrypt zipfile entries (if any). THIS IS INSECURE!

User interaction

-e|--encrypt Encrypt the contents of the zip archive using a password which is entered on the terminal in response to a prompt

Sign up to request clarification or add additional context in comments.

Comments

5

There is a parameter for this see the manpage:

-P password --password password Use password to encrypt 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 standard encryption pro‐ vided by zipfile utilities.) 

EDIT: If this is to unsecure for you use this simple expect script:

#!/usr/bin/expect -f set prompt {$ } set password "secret" #spawn the command spawn zip -er archivename.zip file # Look for passwod prompt (twice) expect "*?assword:*" send "$password\r" expect "*?assword:*" send "$password\r" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.