Last active
May 14, 2024 10:01
-
-
Save slavafomin/7114c76a55a2d89e4119a56aa52cd484 to your computer and use it in GitHub Desktop.
Revisions
-
slavafomin revised this gist
May 14, 2024 . 2 changed files with 54 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # GPG Encryption ## List Keys This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ #!/usr/bin/env bash # This is an example of a backup script that # creates encrypted archive of a JavaScript project. # The "vars" file should be created alongside # this script with the following vars: # # BACKUP_PATH="/home/username/backup.tgz.gpg" # path to the destination archive # GPG_KEY="12345" # recipient's GPG key # Decrypt it with: # gpg -d filename.gpg > filename.tgz set -e set -o pipefail SCRIPT_PATH="$(dirname "$0")" VARS_PATH=$(realpath "${SCRIPT_PATH}/vars") if [ ! -f "$VARS_PATH" ]; then echo -e "Missing vars file at:\n${VARS_PATH}" echo -e "\nCreate it with \"cp ./bin/vars.dist ./bin/vars\"" exit 1 fi # shellcheck source=../vars source "${VARS_PATH}" if [ -z "${BACKUP_PATH-}" ]; then echo -e "Missing the BACKUP_PATH variable from:\n${VARS_PATH}" exit 1 fi if [ -z "${GPG_KEY-}" ]; then echo -e "Missing the GPG_KEY variable from:\n${VARS_PATH}" exit 1 fi echo -e "Creating archive at:\n${BACKUP_PATH}" echo -e "\nUsing GPG key:\n${GPG_KEY}" tar czf - \ --exclude='.git' \ --exclude='.idea' \ --exclude='dist' \ --exclude='node_modules' \ --exclude='tmp' \ . \ | gpg -e -R "${GPG_KEY}" > "${BACKUP_PATH}" echo -e "\nBackup complete" -
slavafomin revised this gist
May 14, 2024 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,4 +32,10 @@ This decrypts it back: ```shell gpg -d filename.gpg > filename ``` ## Acrhive & Encrypt ```shell tar czf - . | gpg -e > archive.gpg ``` -
slavafomin created this gist
May 14, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ ## List Keys ```shell gpg --list-keys ``` ## Import Key ```shell gpg --import private.key ``` ## Config file ```shell # ~/.gnupg/gpg.conf: default-key {KEY-ID} default-recipient-self ``` ## Encrypt/Decrypt File This encrypts the file using default key (default recipient): ```shell gpg -e filename ``` This decrypts it back: ```shell gpg -d filename.gpg > filename ```