GPG Key Import to Another PC

We have provided a set of commands for working with GPG keys, encrypting and decrypting files, and extracting tar archives. These commands are useful for various tasks related to data security and file management. Here’s a breakdown of each command with a brief explanation:

1
2
3
4
5
6
7
scp example-backup-enc-privkey.asc [email protected]:~/
gpg --import example-backup-enc-privkey.asc
gpg --edit-key [email protected]

> trust
5
quit
  • The scp command is used to securely copy the GPG private key file (example-backup-enc-privkey.asc) to another PC with the specified IP address and destination folder (~ denotes the user’s home directory).

  • gpg --import is used to import the GPG private key into the GPG keyring on the destination PC.

  • gpg --edit-key [email protected] opens an interactive prompt for editing the key with the specified email address.

  • Inside the interactive prompt, trust sets the trust level of the key, and 5 represents “I trust ultimately.” This level indicates a high level of trust in the key.

GPG Encrypt File

1
gpg --encrypt --recipient "Example Backup" test.data
  • This command is used to encrypt a file (test.data) using GPG. The --recipient flag specifies the recipient’s name or key ID. In this case, it’s “Example Backup.”

GPG Decrypt File

1
gpg --output test.data.output --decrypt test.data.gpg
  • This command decrypts a GPG-encrypted file (test.data.gpg) and saves the decrypted content to a file named test.data.output. Make sure you have the necessary decryption key to perform this operation.

GPG Remove Secret Key

1
2
gpg --list-secret-keys
gpg --delete-secret-keys <YOUR-SECRET-KEY>
  • The first command, gpg --list-secret-keys, lists your secret keys.

  • The second command, gpg --delete-secret-keys <YOUR-SECRET-KEY>, deletes the specified secret key from your keyring. Replace <YOUR-SECRET-KEY> with the appropriate key ID.

Extract Tar Archive (Preserving Permissions)

1
2
cd /path/to/destination/folder
tar xpvzf put_your_name_here.tar.gz
  • This set of commands navigates to the destination folder (cd /path/to/destination/folder) and extracts the contents of a tar archive (put_your_name_here.tar.gz) while preserving file permissions and ownership.

Extract Tar Archive (Specific Folder)

1
tar -C ./ -xpvzf foo.tar home/foo/bar
  • This command extracts the contents of the foo.tar archive into the current directory (-C ./) and specifically targets the folder home/foo/bar within the archive for extraction.

Please note that these commands should be used with caution, especially when dealing with GPG keys, as mishandling them can result in data loss or security issues. Always ensure you have backups and understand the implications of the commands you’re using.

0%