Security newbie here
I have a bash script that recursively enumerates all files and directories from a given path (say /home/user
) and encrypts individual files and stores them into another directory (say /media/backup
) maintaining the directory structure. I'm using GPG's symmetric key (AES 128) encryption for the purpose.
Now the problem is that GPG prompts me to enter a password for every file that is to be encrypted. Since there are multiple files, this isn't feasible. So the solutions I could think of are -
- Prompt user to enter the key, and store it in a variable, and use that variable in the script for password (with the
echo $password | gpg ... --passphrase-fd 0 --batch
option). The user has to memorize the password. - Create a new public/private key identity with GPG. Create a new text file containing the password and encrypt it with the public key of this new identity and store it locally. Now in the script, decrypt this password file and use the password thus decrypted. Again in this case, the user enters the (memorized) private key password once.
To me, both the solutions seem similar (user has the final piece required to decrypt the files). I would like to know if one solution is better than the other, or even if they both are insecure; and in that case what should be the ideal solution.
The threat model here is, if my encrypted files & my system is compromised and an adversary gets user/root access to my system, they shouldn't be able to decrypt the files without the memorized password.
Edit: The person posting this question (https://stackoverflow.com/questions/3491481/encrypting-large-files-using-a-public-key) claims that symmetric encryption of files and then asymmetric encryption of the key is the proper way to do it. Does that imply #2 is the preferred way?