Scripting
使用密碼的zip文件問題
我有一個
.txt
文件,我有一個 bash 腳本,其中 txt 文件將被壓縮並移動到其他 sftp 伺服器。我在用
zip -P pass foo.zip foo.txt
在腳本中,密碼是可見的,但我不應該在那裡保存硬編碼的密碼。誰能幫我嗎?
從
zip
手冊頁,-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 provided by zipfile utilities.)
正如手冊頁中提到的那樣,這是非常不安全的!
因此,您可以嘗試以下操作,
zip
再次從手冊頁中,--encrypt Encrypt the contents of the zip archive using a password which is entered on the terminal in response to a prompt (this will not be echoed; if standard error is not a tty, zip will exit with an error). The password prompt is repeated to save the user from typing errors.
該命令類似於,
zip --encrypt foo.zip foo.txt
在終端上要求輸入密碼,Enter password: Verify password: updating: foo.txt (stored 0%)
**警告:**所使用的加密
zip
並不是真正強大的加密。它很容易被破解!