在Linux上使用OpenSSL進行文件加密傳輸,可以通過以下步驟實現:
首先,確保你的系統上已經安裝了OpenSSL。如果沒有安裝,可以使用以下命令進行安裝:
sudo apt-get update
sudo apt-get install openssl
為了加密和解密文件,你需要生成一對公鑰和私鑰。公鑰用于加密,私鑰用于解密。
# 生成私鑰
openssl genpkey -algorithm RSA -out private_key.pem -aes256
# 生成公鑰
openssl rsa -pubout -in private_key.pem -out public_key.pem
使用接收方的公鑰加密文件。
openssl rsautl -encrypt -pubin -inkey public_key.pem -in plaintext_file.txt -out encrypted_file.enc
使用接收方的私鑰解密文件。
openssl rsautl -decrypt -inkey private_key.pem -in encrypted_file.enc -out decrypted_file.txt
將加密后的文件(例如 encrypted_file.enc
)傳輸到接收方??梢允褂?scp
或其他文件傳輸工具。
scp encrypted_file.enc user@remote_host:/path/to/destination
接收方使用自己的私鑰解密文件。
openssl rsautl -decrypt -inkey private_key.pem -in encrypted_file.enc -out decrypted_file.txt
為了安全起見,刪除臨時文件。
rm encrypted_file.enc
rm decrypted_file.txt
scp
或 rsync
)來傳輸加密文件。通過以上步驟,你可以在Linux上使用OpenSSL實現文件的加密傳輸。