想要使用密码保护我的ZIP存档。
使用以下方式创建存档:
zip -er archivename.zip file
得到这个:
Enter password:
Verify password:
一切都很好,但我有密码变量,需要将此密码发送到zip
。通过这样的论点尝试,但失败了。
echo "$1"| zip -er archivename.zip file
bash有可能吗?因为zip实用程序不支持stdin
。
答案 0 :(得分:4)
有一个参数可以参见联机帮助页:
-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.)
编辑:如果这是为了不安全,请使用这个简单的expect
脚本:
#!/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"
答案 1 :(得分:1)
对于不安全的解决方案,请使用-P
:
-P | --password密码使用密码加密 zipfile条目(如果有)。 这是不安全的!
-e | --encrypt使用密码在终端上输入来加密zip存档的内容以响应提示