Skip to content

Instantly share code, notes, and snippets.

@johnnyopao
Created May 2, 2018 23:42
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnnyopao/33c6500bda474a7afb33207489d8e8e5 to your computer and use it in GitHub Desktop.
Save johnnyopao/33c6500bda474a7afb33207489d8e8e5 to your computer and use it in GitHub Desktop.
GPG Encrypt all files in directory
#!/bin/bash
# This uses gpg to encrypt every file in a directory as separate
# encrypted files
# Usage
# ./encrypt-all.sh ./dir-of-files-to-encrypt "PASSPHRASE"
FILES="$1"
PASSPHRASE="$2"
pushd $FILES
for file_name in ./*; do
enc_name="$file_name.enc"
echo "Encrypting $file_name"
gpg \
--passphrase "$PASSPHRASE" \
--batch \
--output "$file_name.enc" \
--symmetric \
--cipher-algo AES256 \
"$file_name"
echo "Done! Output: $enc_name"
done
popd
@robertkeogh
Copy link

I get the following error when I try to run the above script even with sudo

@robertkeogh
Copy link

./encrypt-all.sh: command not found

@johnnyopao
Copy link
Author

@robertkeogh it might be that you don't have gpg installed. If you don't have it, here's an article that has installation steps

http://blog.ghostinthemachines.com/2015/03/01/how-to-use-gpg-command-line/

@olekstomek
Copy link

works perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment