Ale*_*ern 3 unix bash terminal zip stdin
想用密码保护我的 ZIP 档案。
用这个创建存档:
zip -er archivename.zip file
Run Code Online (Sandbox Code Playgroud)
得到这个:
Enter password:
Verify password:
Run Code Online (Sandbox Code Playgroud)
一切正常,但我有密码变量,需要将此密码发送到zip
. 尝试过这样的论点,但失败了。
echo "$1"| zip -er archivename.zip file
Run Code Online (Sandbox Code Playgroud)
在 bash 中可能吗?因为 zip 实用程序不支持stdin
.
有一个参数,请参见联机帮助页:
-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.)
Run Code Online (Sandbox Code Playgroud)
编辑:如果这对您来说不安全,请使用这个简单的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"
Run Code Online (Sandbox Code Playgroud)
对于不安全的解决方案,请使用-P
:
-P|--password password 使用密码来加密 zipfile 条目(如果有)。 这是不安全的!
-e|--encrypt 使用在终端上输入的密码来加密 zip 存档的内容以响应提示
归档时间: |
|
查看次数: |
2145 次 |
最近记录: |